88 DatePrototypeGetTime,
99 ErrorCaptureStackTrace,
1010 FunctionPrototypeCall,
11+ MathFloor,
1112 MathMin,
1213 MathRound,
1314 Number,
@@ -63,6 +64,10 @@ const {
6364const pathModule = require ( 'path' ) ;
6465const kType = Symbol ( 'type' ) ;
6566const kStats = Symbol ( 'stats' ) ;
67+ const kPartialAtimeNs = Symbol ( 'partialAtimeNs' ) ;
68+ const kPartialMtimeNs = Symbol ( 'partialMtimeNs' ) ;
69+ const kPartialCtimeNs = Symbol ( 'partialCtimeNs' ) ;
70+ const kPartialBirthtimeNs = Symbol ( 'kPartialBirthtimeNs' ) ;
6671const assert = require ( 'internal/assert' ) ;
6772
6873const {
@@ -431,6 +436,11 @@ function nsFromTimeSpecBigInt(sec, nsec) {
431436 return sec * kNsPerSecBigInt + nsec ;
432437}
433438
439+ function instantFromTimeSpecMs ( msec , nsec ) {
440+ // TODO(LiviaMedeiros): TemporalInstant primordial
441+ return new Temporal . Instant ( BigInt ( MathFloor ( msec / kMsPerSec ) ) * kNsPerSecBigInt + BigInt ( nsec ) ) ;
442+ }
443+
434444// The Date constructor performs Math.floor() on the absolute value
435445// of the timestamp: https://tc39.es/ecma262/#sec-timeclip
436446// Since there may be a precision loss when the timestamp is
@@ -491,6 +501,102 @@ const lazyDateFields = {
491501 } ,
492502} ;
493503
504+ const lazyTemporalFields = {
505+ __proto__ : null ,
506+ atimeInstant : {
507+ __proto__ : null ,
508+ enumerable : true ,
509+ configurable : true ,
510+ get ( ) {
511+ return this . atimeInstant = instantFromTimeSpecMs ( this . atimeMs , this [ kPartialAtimeNs ] ) ;
512+ } ,
513+ set ( value ) {
514+ ObjectDefineProperty ( this , 'atimeInstant' , { __proto__ : null , value, writable : true } ) ;
515+ } ,
516+ } ,
517+ mtimeInstant : {
518+ __proto__ : null ,
519+ enumerable : true ,
520+ configurable : true ,
521+ get ( ) {
522+ return this . mtimeInstant = instantFromTimeSpecMs ( this . mtimeMs , this [ kPartialMtimeNs ] ) ;
523+ } ,
524+ set ( value ) {
525+ ObjectDefineProperty ( this , 'mtimeInstant' , { __proto__ : null , value, writable : true } ) ;
526+ } ,
527+ } ,
528+ ctimeInstant : {
529+ __proto__ : null ,
530+ enumerable : true ,
531+ configurable : true ,
532+ get ( ) {
533+ return this . ctimeInstant = instantFromTimeSpecMs ( this . ctimeMs , this [ kPartialCtimeNs ] ) ; ;
534+ } ,
535+ set ( value ) {
536+ ObjectDefineProperty ( this , 'ctimeInstant' , { __proto__ : null , value, writable : true } ) ;
537+ } ,
538+ } ,
539+ birthtimeInstant : {
540+ __proto__ : null ,
541+ enumerable : true ,
542+ configurable : true ,
543+ get ( ) {
544+ return this . birthtimeInstant = instantFromTimeSpecMs ( this . birthtimeMs , this [ kPartialBirthtimeNs ] ) ; ;
545+ } ,
546+ set ( value ) {
547+ ObjectDefineProperty ( this , 'birthtimeInstant' , { __proto__ : null , value, writable : true } ) ;
548+ } ,
549+ } ,
550+ } ;
551+
552+ const lazyTemporalBigIntFields = {
553+ __proto__ : null ,
554+ atimeInstant : {
555+ __proto__ : null ,
556+ enumerable : true ,
557+ configurable : true ,
558+ get ( ) {
559+ return this . atimeInstant = new Temporal . Instant ( this . atimeNs ) ;
560+ } ,
561+ set ( value ) {
562+ ObjectDefineProperty ( this , 'atimeInstant' , { __proto__ : null , value, writable : true } ) ;
563+ } ,
564+ } ,
565+ mtimeInstant : {
566+ __proto__ : null ,
567+ enumerable : true ,
568+ configurable : true ,
569+ get ( ) {
570+ return this . mtimeInstant = new Temporal . Instant ( this . mtimeNs ) ;
571+ } ,
572+ set ( value ) {
573+ ObjectDefineProperty ( this , 'mtimeInstant' , { __proto__ : null , value, writable : true } ) ;
574+ } ,
575+ } ,
576+ ctimeInstant : {
577+ __proto__ : null ,
578+ enumerable : true ,
579+ configurable : true ,
580+ get ( ) {
581+ return this . ctimeInstant = new Temporal . Instant ( this . ctimeNs ) ;
582+ } ,
583+ set ( value ) {
584+ ObjectDefineProperty ( this , 'ctimeInstant' , { __proto__ : null , value, writable : true } ) ;
585+ } ,
586+ } ,
587+ birthtimeInstant : {
588+ __proto__ : null ,
589+ enumerable : true ,
590+ configurable : true ,
591+ get ( ) {
592+ return this . birthtimeInstant = new Temporal . Instant ( this . birthtimeNs ) ;
593+ } ,
594+ set ( value ) {
595+ ObjectDefineProperty ( this , 'birthtimeInstant' , { __proto__ : null , value, writable : true } ) ;
596+ } ,
597+ } ,
598+ } ;
599+
494600function BigIntStats ( dev , mode , nlink , uid , gid , rdev , blksize ,
495601 ino , size , blocks ,
496602 atimeNs , mtimeNs , ctimeNs , birthtimeNs ) {
@@ -510,6 +616,7 @@ function BigIntStats(dev, mode, nlink, uid, gid, rdev, blksize,
510616ObjectSetPrototypeOf ( BigIntStats . prototype , StatsBase . prototype ) ;
511617ObjectSetPrototypeOf ( BigIntStats , StatsBase ) ;
512618ObjectDefineProperties ( BigIntStats . prototype , lazyDateFields ) ;
619+ ObjectDefineProperties ( BigIntStats . prototype , lazyTemporalBigIntFields ) ;
513620
514621BigIntStats . prototype . _checkModeProperty = function ( property ) {
515622 if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
@@ -521,18 +628,23 @@ BigIntStats.prototype._checkModeProperty = function(property) {
521628
522629function Stats ( dev , mode , nlink , uid , gid , rdev , blksize ,
523630 ino , size , blocks ,
524- atimeMs , mtimeMs , ctimeMs , birthtimeMs ) {
631+ atimeS , atimeNs , mtimeS , mtimeNs , ctimeS , ctimeNs , birthtimeS , birthtimeNs ) {
525632 FunctionPrototypeCall ( StatsBase , this , dev , mode , nlink , uid , gid , rdev ,
526633 blksize , ino , size , blocks ) ;
527- this . atimeMs = atimeMs ;
528- this . mtimeMs = mtimeMs ;
529- this . ctimeMs = ctimeMs ;
530- this . birthtimeMs = birthtimeMs ;
634+ this . atimeMs = msFromTimeSpec ( atimeS , atimeNs ) ;
635+ this . mtimeMs = msFromTimeSpec ( mtimeS , mtimeNs ) ;
636+ this . ctimeMs = msFromTimeSpec ( ctimeS , ctimeNs ) ;
637+ this . birthtimeMs = msFromTimeSpec ( birthtimeS , birthtimeNs ) ;
638+ this [ kPartialAtimeNs ] = atimeNs ;
639+ this [ kPartialMtimeNs ] = mtimeNs ;
640+ this [ kPartialCtimeNs ] = ctimeNs ;
641+ this [ kPartialBirthtimeNs ] = birthtimeNs ;
531642}
532643
533644ObjectSetPrototypeOf ( Stats . prototype , StatsBase . prototype ) ;
534645ObjectSetPrototypeOf ( Stats , StatsBase ) ;
535646ObjectDefineProperties ( Stats . prototype , lazyDateFields ) ;
647+ ObjectDefineProperties ( Stats . prototype , lazyTemporalFields ) ;
536648
537649Stats . prototype . _checkModeProperty = function ( property ) {
538650 if ( isWindows && ( property === S_IFIFO || property === S_IFBLK ||
@@ -565,10 +677,10 @@ function getStatsFromBinding(stats, offset = 0) {
565677 stats [ 3 + offset ] , stats [ 4 + offset ] , stats [ 5 + offset ] ,
566678 stats [ 6 + offset ] , stats [ 7 + offset ] , stats [ 8 + offset ] ,
567679 stats [ 9 + offset ] ,
568- msFromTimeSpec ( stats [ 10 + offset ] , stats [ 11 + offset ] ) ,
569- msFromTimeSpec ( stats [ 12 + offset ] , stats [ 13 + offset ] ) ,
570- msFromTimeSpec ( stats [ 14 + offset ] , stats [ 15 + offset ] ) ,
571- msFromTimeSpec ( stats [ 16 + offset ] , stats [ 17 + offset ] ) ,
680+ stats [ 10 + offset ] , stats [ 11 + offset ] , // atime
681+ stats [ 12 + offset ] , stats [ 13 + offset ] , // mtime
682+ stats [ 14 + offset ] , stats [ 15 + offset ] , // ctime
683+ stats [ 16 + offset ] , stats [ 17 + offset ] , // birthtime
572684 ) ;
573685}
574686
0 commit comments