88 DatePrototypeGetTime,
99 ErrorCaptureStackTrace,
1010 FunctionPrototypeCall,
11+ MathFloor,
1112 MathMin,
1213 MathRound,
1314 Number,
@@ -22,6 +23,7 @@ const {
2223 Symbol,
2324 TypedArrayPrototypeAt,
2425 TypedArrayPrototypeIncludes,
26+ globalThis,
2527} = primordials ;
2628
2729const { Buffer } = require ( 'buffer' ) ;
@@ -32,6 +34,7 @@ const {
3234 ERR_INCOMPATIBLE_OPTION_PAIR ,
3335 ERR_INVALID_ARG_TYPE ,
3436 ERR_INVALID_ARG_VALUE ,
37+ ERR_NO_TEMPORAL ,
3538 ERR_OUT_OF_RANGE ,
3639 } ,
3740 hideStackFrames,
@@ -43,10 +46,10 @@ const {
4346 isUint8Array,
4447} = require ( 'internal/util/types' ) ;
4548const {
46- kEmptyObject,
47- once,
4849 deprecate,
4950 isWindows,
51+ kEmptyObject,
52+ once,
5053 setOwnProperty,
5154} = require ( 'internal/util' ) ;
5255const { toPathIfFileURL } = require ( 'internal/url' ) ;
@@ -62,6 +65,10 @@ const {
6265const pathModule = require ( 'path' ) ;
6366const kType = Symbol ( 'type' ) ;
6467const kStats = Symbol ( 'stats' ) ;
68+ const kPartialAtimeNs = Symbol ( 'partialAtimeNs' ) ;
69+ const kPartialMtimeNs = Symbol ( 'partialMtimeNs' ) ;
70+ const kPartialCtimeNs = Symbol ( 'partialCtimeNs' ) ;
71+ const kPartialBirthtimeNs = Symbol ( 'kPartialBirthtimeNs' ) ;
6572const assert = require ( 'internal/assert' ) ;
6673
6774const {
@@ -430,6 +437,25 @@ function nsFromTimeSpecBigInt(sec, nsec) {
430437 return sec * kNsPerSecBigInt + nsec ;
431438}
432439
440+ // TODO(LiviaMedeiros): TemporalInstant primordial
441+ let TemporalInstant ;
442+
443+ function instantFromNs ( nsec ) {
444+ TemporalInstant ??= globalThis . Temporal . Instant ;
445+ if ( TemporalInstant === undefined ) {
446+ throw new ERR_NO_TEMPORAL ( ) ;
447+ }
448+ return new TemporalInstant ( nsec ) ;
449+ }
450+
451+ function instantFromTimeSpecMs ( msec , nsec ) {
452+ TemporalInstant ??= globalThis . Temporal . Instant ;
453+ if ( TemporalInstant === undefined ) {
454+ throw new ERR_NO_TEMPORAL ( ) ;
455+ }
456+ return new TemporalInstant ( BigInt ( MathFloor ( msec / kMsPerSec ) ) * kNsPerSecBigInt + BigInt ( nsec ) ) ;
457+ }
458+
433459// The Date constructor performs Math.floor() on the absolute value
434460// of the timestamp: https://tc39.es/ecma262/#sec-timeclip
435461// Since there may be a precision loss when the timestamp is
@@ -490,6 +516,118 @@ const lazyDateFields = {
490516 } ,
491517} ;
492518
519+ const lazyTemporalFields = {
520+ __proto__ : null ,
521+ atimeInstant : {
522+ __proto__ : null ,
523+ enumerable : true ,
524+ configurable : true ,
525+ get ( ) {
526+ const value = instantFromTimeSpecMs ( this . atimeMs , this [ kPartialAtimeNs ] ) ;
527+ setOwnProperty ( this , 'atimeInstant' , value ) ;
528+ return value ;
529+ } ,
530+ set ( value ) {
531+ setOwnProperty ( this , 'atimeInstant' , value ) ;
532+ } ,
533+ } ,
534+ mtimeInstant : {
535+ __proto__ : null ,
536+ enumerable : true ,
537+ configurable : true ,
538+ get ( ) {
539+ const value = instantFromTimeSpecMs ( this . mtimeMs , this [ kPartialMtimeNs ] ) ;
540+ setOwnProperty ( this , 'mtimeInstant' , value ) ;
541+ return value ;
542+ } ,
543+ set ( value ) {
544+ setOwnProperty ( this , 'mtimeInstant' , value ) ;
545+ } ,
546+ } ,
547+ ctimeInstant : {
548+ __proto__ : null ,
549+ enumerable : true ,
550+ configurable : true ,
551+ get ( ) {
552+ const value = instantFromTimeSpecMs ( this . ctimeMs , this [ kPartialCtimeNs ] ) ;
553+ setOwnProperty ( this , 'ctimeInstant' , value ) ;
554+ return value ;
555+ } ,
556+ set ( value ) {
557+ setOwnProperty ( this , 'ctimeInstant' , value ) ;
558+ } ,
559+ } ,
560+ birthtimeInstant : {
561+ __proto__ : null ,
562+ enumerable : true ,
563+ configurable : true ,
564+ get ( ) {
565+ const value = instantFromTimeSpecMs ( this . birthtimeMs , this [ kPartialBirthtimeNs ] ) ;
566+ setOwnProperty ( this , 'birthtimeInstant' , value ) ;
567+ return value ;
568+ } ,
569+ set ( value ) {
570+ setOwnProperty ( this , 'birthtimeInstant' , value ) ;
571+ } ,
572+ } ,
573+ } ;
574+
575+ const lazyTemporalBigIntFields = {
576+ __proto__ : null ,
577+ atimeInstant : {
578+ __proto__ : null ,
579+ enumerable : true ,
580+ configurable : true ,
581+ get ( ) {
582+ const value = instantFromNs ( this . atimeNs ) ;
583+ setOwnProperty ( this , 'atimeInstant' , value ) ;
584+ return value ;
585+ } ,
586+ set ( value ) {
587+ setOwnProperty ( this , 'atimeInstant' , value ) ;
588+ } ,
589+ } ,
590+ mtimeInstant : {
591+ __proto__ : null ,
592+ enumerable : true ,
593+ configurable : true ,
594+ get ( ) {
595+ const value = instantFromNs ( this . mtimeNs ) ;
596+ setOwnProperty ( this , 'mtimeInstant' , value ) ;
597+ return value ;
598+ } ,
599+ set ( value ) {
600+ setOwnProperty ( this , 'mtimeInstant' , value ) ;
601+ } ,
602+ } ,
603+ ctimeInstant : {
604+ __proto__ : null ,
605+ enumerable : true ,
606+ configurable : true ,
607+ get ( ) {
608+ const value = instantFromNs ( this . ctimeNs ) ;
609+ setOwnProperty ( this , 'ctimeInstant' , value ) ;
610+ return value ;
611+ } ,
612+ set ( value ) {
613+ setOwnProperty ( this , 'ctimeInstant' , value ) ;
614+ } ,
615+ } ,
616+ birthtimeInstant : {
617+ __proto__ : null ,
618+ enumerable : true ,
619+ configurable : true ,
620+ get ( ) {
621+ const value = instantFromNs ( this . birthtimeNs ) ;
622+ setOwnProperty ( this , 'birthtimeInstant' , value ) ;
623+ return value ;
624+ } ,
625+ set ( value ) {
626+ setOwnProperty ( this , 'birthtimeInstant' , value ) ;
627+ } ,
628+ } ,
629+ } ;
630+
493631function BigIntStats ( dev , mode , nlink , uid , gid , rdev , blksize ,
494632 ino , size , blocks ,
495633 atimeNs , mtimeNs , ctimeNs , birthtimeNs ) {
@@ -508,6 +646,7 @@ function BigIntStats(dev, mode, nlink, uid, gid, rdev, blksize,
508646ObjectSetPrototypeOf ( BigIntStats . prototype , StatsBase . prototype ) ;
509647ObjectSetPrototypeOf ( BigIntStats , StatsBase ) ;
510648ObjectDefineProperties ( BigIntStats . prototype , lazyDateFields ) ;
649+ ObjectDefineProperties ( BigIntStats . prototype , lazyTemporalBigIntFields ) ;
511650
512651BigIntStats . prototype . _checkModeProperty = function ( property ) {
513652 if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
@@ -519,18 +658,23 @@ BigIntStats.prototype._checkModeProperty = function(property) {
519658
520659function Stats ( dev , mode , nlink , uid , gid , rdev , blksize ,
521660 ino , size , blocks ,
522- atimeMs , mtimeMs , ctimeMs , birthtimeMs ) {
661+ atimeS , atimeNs , mtimeS , mtimeNs , ctimeS , ctimeNs , birthtimeS , birthtimeNs ) {
523662 FunctionPrototypeCall ( StatsBase , this , dev , mode , nlink , uid , gid , rdev ,
524663 blksize , ino , size , blocks ) ;
525- this . atimeMs = atimeMs ;
526- this . mtimeMs = mtimeMs ;
527- this . ctimeMs = ctimeMs ;
528- this . birthtimeMs = birthtimeMs ;
664+ this . atimeMs = msFromTimeSpec ( atimeS , atimeNs ) ;
665+ this . mtimeMs = msFromTimeSpec ( mtimeS , mtimeNs ) ;
666+ this . ctimeMs = msFromTimeSpec ( ctimeS , ctimeNs ) ;
667+ this . birthtimeMs = msFromTimeSpec ( birthtimeS , birthtimeNs ) ;
668+ this [ kPartialAtimeNs ] = atimeNs ;
669+ this [ kPartialMtimeNs ] = mtimeNs ;
670+ this [ kPartialCtimeNs ] = ctimeNs ;
671+ this [ kPartialBirthtimeNs ] = birthtimeNs ;
529672}
530673
531674ObjectSetPrototypeOf ( Stats . prototype , StatsBase . prototype ) ;
532675ObjectSetPrototypeOf ( Stats , StatsBase ) ;
533676ObjectDefineProperties ( Stats . prototype , lazyDateFields ) ;
677+ ObjectDefineProperties ( Stats . prototype , lazyTemporalFields ) ;
534678
535679Stats . prototype . _checkModeProperty = function ( property ) {
536680 if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
@@ -563,10 +707,10 @@ function getStatsFromBinding(stats, offset = 0) {
563707 stats [ 3 + offset ] , stats [ 4 + offset ] , stats [ 5 + offset ] ,
564708 stats [ 6 + offset ] , stats [ 7 + offset ] , stats [ 8 + offset ] ,
565709 stats [ 9 + offset ] ,
566- msFromTimeSpec ( stats [ 10 + offset ] , stats [ 11 + offset ] ) ,
567- msFromTimeSpec ( stats [ 12 + offset ] , stats [ 13 + offset ] ) ,
568- msFromTimeSpec ( stats [ 14 + offset ] , stats [ 15 + offset ] ) ,
569- msFromTimeSpec ( stats [ 16 + offset ] , stats [ 17 + offset ] ) ,
710+ stats [ 10 + offset ] , stats [ 11 + offset ] , // atime
711+ stats [ 12 + offset ] , stats [ 13 + offset ] , // mtime
712+ stats [ 14 + offset ] , stats [ 15 + offset ] , // ctime
713+ stats [ 16 + offset ] , stats [ 17 + offset ] , // birthtime
570714 ) ;
571715}
572716
0 commit comments