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,106 @@ 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+ return setOwnProperty ( this , 'atimeInstant' ,
527+ instantFromTimeSpecMs ( this . atimeMs , this [ kPartialAtimeNs ] ) ) ;
528+ } ,
529+ set ( value ) {
530+ setOwnProperty ( this , 'atimeInstant' , value ) ;
531+ } ,
532+ } ,
533+ mtimeInstant : {
534+ __proto__ : null ,
535+ enumerable : true ,
536+ configurable : true ,
537+ get ( ) {
538+ return setOwnProperty ( this , 'mtimeInstant' ,
539+ instantFromTimeSpecMs ( this . mtimeMs , this [ kPartialMtimeNs ] ) ) ;
540+ } ,
541+ set ( value ) {
542+ setOwnProperty ( this , 'mtimeInstant' , value ) ;
543+ } ,
544+ } ,
545+ ctimeInstant : {
546+ __proto__ : null ,
547+ enumerable : true ,
548+ configurable : true ,
549+ get ( ) {
550+ return setOwnProperty ( this , 'ctimeInstant' ,
551+ instantFromTimeSpecMs ( this . ctimeMs , this [ kPartialCtimeNs ] ) ) ;
552+ } ,
553+ set ( value ) {
554+ setOwnProperty ( this , 'ctimeInstant' , value ) ;
555+ } ,
556+ } ,
557+ birthtimeInstant : {
558+ __proto__ : null ,
559+ enumerable : true ,
560+ configurable : true ,
561+ get ( ) {
562+ return setOwnProperty ( this , 'birthtimeInstant' ,
563+ instantFromTimeSpecMs ( this . birthtimeMs , this [ kPartialBirthtimeNs ] ) ) ;
564+ } ,
565+ set ( value ) {
566+ setOwnProperty ( this , 'birthtimeInstant' , value ) ;
567+ } ,
568+ } ,
569+ } ;
570+
571+ const lazyTemporalBigIntFields = {
572+ __proto__ : null ,
573+ atimeInstant : {
574+ __proto__ : null ,
575+ enumerable : true ,
576+ configurable : true ,
577+ get ( ) {
578+ return setOwnProperty ( this , 'atimeInstant' , instantFromNs ( this . atimeNs ) ) ;
579+ } ,
580+ set ( value ) {
581+ setOwnProperty ( this , 'atimeInstant' , value ) ;
582+ } ,
583+ } ,
584+ mtimeInstant : {
585+ __proto__ : null ,
586+ enumerable : true ,
587+ configurable : true ,
588+ get ( ) {
589+ return setOwnProperty ( this , 'mtimeInstant' , instantFromNs ( this . mtimeNs ) ) ;
590+ } ,
591+ set ( value ) {
592+ setOwnProperty ( this , 'mtimeInstant' , value ) ;
593+ } ,
594+ } ,
595+ ctimeInstant : {
596+ __proto__ : null ,
597+ enumerable : true ,
598+ configurable : true ,
599+ get ( ) {
600+ return setOwnProperty ( this , 'ctimeInstant' , instantFromNs ( this . ctimeNs ) ) ;
601+ } ,
602+ set ( value ) {
603+ setOwnProperty ( this , 'ctimeInstant' , value ) ;
604+ } ,
605+ } ,
606+ birthtimeInstant : {
607+ __proto__ : null ,
608+ enumerable : true ,
609+ configurable : true ,
610+ get ( ) {
611+ return setOwnProperty ( this , 'birthtimeInstant' , instantFromNs ( this . birthtimeNs ) ) ;
612+ } ,
613+ set ( value ) {
614+ setOwnProperty ( this , 'birthtimeInstant' , value ) ;
615+ } ,
616+ } ,
617+ } ;
618+
493619function BigIntStats ( dev , mode , nlink , uid , gid , rdev , blksize ,
494620 ino , size , blocks ,
495621 atimeNs , mtimeNs , ctimeNs , birthtimeNs ) {
@@ -508,6 +634,7 @@ function BigIntStats(dev, mode, nlink, uid, gid, rdev, blksize,
508634ObjectSetPrototypeOf ( BigIntStats . prototype , StatsBase . prototype ) ;
509635ObjectSetPrototypeOf ( BigIntStats , StatsBase ) ;
510636ObjectDefineProperties ( BigIntStats . prototype , lazyDateFields ) ;
637+ ObjectDefineProperties ( BigIntStats . prototype , lazyTemporalBigIntFields ) ;
511638
512639BigIntStats . prototype . _checkModeProperty = function ( property ) {
513640 if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
@@ -519,18 +646,23 @@ BigIntStats.prototype._checkModeProperty = function(property) {
519646
520647function Stats ( dev , mode , nlink , uid , gid , rdev , blksize ,
521648 ino , size , blocks ,
522- atimeMs , mtimeMs , ctimeMs , birthtimeMs ) {
649+ atimeS , atimeNs , mtimeS , mtimeNs , ctimeS , ctimeNs , birthtimeS , birthtimeNs ) {
523650 FunctionPrototypeCall ( StatsBase , this , dev , mode , nlink , uid , gid , rdev ,
524651 blksize , ino , size , blocks ) ;
525- this . atimeMs = atimeMs ;
526- this . mtimeMs = mtimeMs ;
527- this . ctimeMs = ctimeMs ;
528- this . birthtimeMs = birthtimeMs ;
652+ this . atimeMs = msFromTimeSpec ( atimeS , atimeNs ) ;
653+ this . mtimeMs = msFromTimeSpec ( mtimeS , mtimeNs ) ;
654+ this . ctimeMs = msFromTimeSpec ( ctimeS , ctimeNs ) ;
655+ this . birthtimeMs = msFromTimeSpec ( birthtimeS , birthtimeNs ) ;
656+ this [ kPartialAtimeNs ] = atimeNs ;
657+ this [ kPartialMtimeNs ] = mtimeNs ;
658+ this [ kPartialCtimeNs ] = ctimeNs ;
659+ this [ kPartialBirthtimeNs ] = birthtimeNs ;
529660}
530661
531662ObjectSetPrototypeOf ( Stats . prototype , StatsBase . prototype ) ;
532663ObjectSetPrototypeOf ( Stats , StatsBase ) ;
533664ObjectDefineProperties ( Stats . prototype , lazyDateFields ) ;
665+ ObjectDefineProperties ( Stats . prototype , lazyTemporalFields ) ;
534666
535667Stats . prototype . _checkModeProperty = function ( property ) {
536668 if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
@@ -563,10 +695,10 @@ function getStatsFromBinding(stats, offset = 0) {
563695 stats [ 3 + offset ] , stats [ 4 + offset ] , stats [ 5 + offset ] ,
564696 stats [ 6 + offset ] , stats [ 7 + offset ] , stats [ 8 + offset ] ,
565697 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 ] ) ,
698+ stats [ 10 + offset ] , stats [ 11 + offset ] , // atime
699+ stats [ 12 + offset ] , stats [ 13 + offset ] , // mtime
700+ stats [ 14 + offset ] , stats [ 15 + offset ] , // ctime
701+ stats [ 16 + offset ] , stats [ 17 + offset ] , // birthtime
570702 ) ;
571703}
572704
0 commit comments