@@ -12,6 +12,14 @@ import {
1212 DateTime as LuxonDateTime ,
1313 FixedOffsetZone
1414} from 'luxon' ;
15+ import {
16+ MAX_DATE_VALUE_STRING ,
17+ MAX_DATETIME_VALUE_STRING ,
18+ MAX_TIME_VALUE_STRING ,
19+ MIN_DATE_VALUE_STRING ,
20+ MIN_DATETIME_VALUE_STRING ,
21+ MIN_TIME_VALUE_STRING
22+ } from '../util/limits' ;
1523
1624// It's easiest and most performant to organize formats by length of the supported strings.
1725// This way we can test strings only against the formats that have a chance of working.
@@ -550,7 +558,7 @@ abstract class AbstractDate {
550558 case 'millisecond' :
551559 return 999 ;
552560 default :
553- throw new Error ( 'Tried to clieling a field that has no cieling value: ' + field ) ;
561+ throw new Error ( 'Tried to ceiling a field that has no cieling value: ' + field ) ;
554562 }
555563 }
556564}
@@ -722,8 +730,10 @@ export class DateTime extends AbstractDate {
722730 ) ;
723731 }
724732
725- successor ( ) {
726- if ( this . millisecond != null ) {
733+ successor ( precision ?: string ) {
734+ if ( precision ) {
735+ return this . add ( 1 , precision ) ;
736+ } else if ( this . millisecond != null ) {
727737 return this . add ( 1 , DateTime . Unit . MILLISECOND ) ;
728738 } else if ( this . second != null ) {
729739 return this . add ( 1 , DateTime . Unit . SECOND ) ;
@@ -740,8 +750,10 @@ export class DateTime extends AbstractDate {
740750 }
741751 }
742752
743- predecessor ( ) {
744- if ( this . millisecond != null ) {
753+ predecessor ( precision ?: string ) {
754+ if ( precision ) {
755+ return this . add ( - 1 , precision ) ;
756+ } else if ( this . millisecond != null ) {
745757 return this . add ( - 1 , DateTime . Unit . MILLISECOND ) ;
746758 } else if ( this . second != null ) {
747759 return this . add ( - 1 , DateTime . Unit . SECOND ) ;
@@ -1078,8 +1090,10 @@ export class Date extends AbstractDate {
10781090 return new Date ( this . year , this . month , this . day ) ;
10791091 }
10801092
1081- successor ( ) {
1082- if ( this . day != null ) {
1093+ successor ( precision ?: string ) {
1094+ if ( precision ) {
1095+ return this . add ( 1 , precision ) ;
1096+ } else if ( this . day != null ) {
10831097 return this . add ( 1 , Date . Unit . DAY ) ;
10841098 } else if ( this . month != null ) {
10851099 return this . add ( 1 , Date . Unit . MONTH ) ;
@@ -1088,8 +1102,10 @@ export class Date extends AbstractDate {
10881102 }
10891103 }
10901104
1091- predecessor ( ) {
1092- if ( this . day != null ) {
1105+ predecessor ( precision ?: string ) {
1106+ if ( precision ) {
1107+ return this . add ( - 1 , precision ) ;
1108+ } else if ( this . day != null ) {
10931109 return this . add ( - 1 , Date . Unit . DAY ) ;
10941110 } else if ( this . month != null ) {
10951111 return this . add ( - 1 , Date . Unit . MONTH ) ;
@@ -1252,15 +1268,12 @@ export class Date extends AbstractDate {
12521268 }
12531269}
12541270
1255- // Require MIN/MAX here because math.js requires this file, and when we make this file require
1256- // math.js before it exports DateTime and Date, it errors due to the circular dependency...
1257- // const { MAX_DATETIME_VALUE, MIN_DATETIME_VALUE } = require('../util/math');
1258- export const MIN_DATETIME_VALUE = DateTime . parse ( '0001-01-01T00:00:00.000' ) ;
1259- export const MAX_DATETIME_VALUE = DateTime . parse ( '9999-12-31T23:59:59.999' ) ;
1260- export const MIN_DATE_VALUE = Date . parse ( '0001-01-01' ) ;
1261- export const MAX_DATE_VALUE = Date . parse ( '9999-12-31' ) ;
1262- export const MIN_TIME_VALUE = DateTime . parse ( '0000-01-01T00:00:00.000' ) ?. getTime ( ) ;
1263- export const MAX_TIME_VALUE = DateTime . parse ( '0000-01-01T23:59:59.999' ) ?. getTime ( ) ;
1271+ export const MIN_DATETIME_VALUE = DateTime . parse ( MIN_DATETIME_VALUE_STRING ) ;
1272+ export const MAX_DATETIME_VALUE = DateTime . parse ( MAX_DATETIME_VALUE_STRING ) ;
1273+ export const MIN_DATE_VALUE = Date . parse ( MIN_DATE_VALUE_STRING ) ;
1274+ export const MAX_DATE_VALUE = Date . parse ( MAX_DATE_VALUE_STRING ) ;
1275+ export const MIN_TIME_VALUE = DateTime . parse ( MIN_TIME_VALUE_STRING ) ?. getTime ( ) ;
1276+ export const MAX_TIME_VALUE = DateTime . parse ( MAX_TIME_VALUE_STRING ) ?. getTime ( ) ;
12641277
12651278const DATETIME_PRECISION_VALUE_MAP = ( ( ) => {
12661279 const dtpvMap = new Map ( ) ;
0 commit comments