@@ -17,15 +17,19 @@ export const Date_dd_Mmm_yyyy_RegexStr: string = ' *([0-3]*[0-9]-(?:Jan|Feb|Mar|
1717export const Date_Mmm_dd_yyyy_RegexStr : string = ' *((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-3]*[0-9]-\\d{4})' ; // Date like Jan-01-2020
1818
1919export const Date_yyyy_Www_mm_dd_RegexStr : string = ' *(\\d{4}-W[0-5]*[0-9] \\([0-3]*[0-9]-[0-3]*[0-9]\\))'
20- export const Date_yyyy_WwwISO_RegexStr : string = ' *(\\d{4}-W[0-5]*[0-9])'
20+ export const Date_yyyy_WwwISO_RegexStr : string = ' *(\\d{4}-W[0-5]*[0-9][-+]? )'
2121export const Date_yyyy_Www_RegexStr : string = Date_yyyy_WwwISO_RegexStr
2222
23- export const DOT_SEPARATOR = '.'
23+ export const DOT_SEPARATOR = '.' // ASCII 46
2424export const DASH_SEPARATOR = '-'
2525
26- const SLASH_SEPARATOR = '/' // ASCII 47
26+ const SLASH_SEPARATOR = '/' // ASCII 47, right before ASCII 48 = '0'
27+ const COLON_SEPARATOR = ':' // ASCII 58, first non-digit character
2728const PIPE_SEPARATOR = '|' // ASCII 124
2829
30+ const EARLIER_THAN_SLASH_SEPARATOR = DOT_SEPARATOR
31+ const LATER_THAN_SLASH_SEPARATOR = COLON_SEPARATOR
32+
2933export const DEFAULT_NORMALIZATION_PLACES = 8 ; // Fixed width of a normalized number (with leading zeros)
3034
3135// Property escapes:
@@ -62,9 +66,9 @@ export function getNormalizedNumber(s: string = '', separator?: string, places?:
6266 // guarantees correct order (/ = ASCII 47, | = ASCII 124)
6367 if ( separator ) {
6468 const components : Array < string > = s . split ( separator ) . filter ( s => s )
65- return `${ components . map ( ( c ) => prependWithZeros ( c , places ?? DEFAULT_NORMALIZATION_PLACES ) ) . join ( PIPE_SEPARATOR ) } // `
69+ return `${ components . map ( ( c ) => prependWithZeros ( c , places ?? DEFAULT_NORMALIZATION_PLACES ) ) . join ( PIPE_SEPARATOR ) } ${ SLASH_SEPARATOR } ${ SLASH_SEPARATOR } `
6670 } else {
67- return `${ prependWithZeros ( s , places ?? DEFAULT_NORMALIZATION_PLACES ) } // `
71+ return `${ prependWithZeros ( s , places ?? DEFAULT_NORMALIZATION_PLACES ) } ${ SLASH_SEPARATOR } ${ SLASH_SEPARATOR } `
6872 }
6973}
7074
@@ -108,9 +112,9 @@ export function getNormalizedRomanNumber(s: string, separator?: string, places?:
108112 // guarantees correct order (/ = ASCII 47, | = ASCII 124)
109113 if ( separator ) {
110114 const components : Array < string > = s . split ( separator ) . filter ( s => s )
111- return `${ components . map ( ( c ) => prependWithZeros ( romanToIntStr ( c ) , places ?? DEFAULT_NORMALIZATION_PLACES ) ) . join ( PIPE_SEPARATOR ) } // `
115+ return `${ components . map ( ( c ) => prependWithZeros ( romanToIntStr ( c ) , places ?? DEFAULT_NORMALIZATION_PLACES ) ) . join ( PIPE_SEPARATOR ) } ${ SLASH_SEPARATOR } ${ SLASH_SEPARATOR } `
112116 } else {
113- return `${ prependWithZeros ( romanToIntStr ( s ) , places ?? DEFAULT_NORMALIZATION_PLACES ) } // `
117+ return `${ prependWithZeros ( romanToIntStr ( s ) , places ?? DEFAULT_NORMALIZATION_PLACES ) } ${ SLASH_SEPARATOR } ${ SLASH_SEPARATOR } `
114118 }
115119}
116120
@@ -128,7 +132,7 @@ export function getNormalizedDate_NormalizerFn_for(separator: string, dayIdx: nu
128132 const monthValue = months ? `${ 1 + MONTHS . indexOf ( components [ monthIdx ] ) } ` : components [ monthIdx ]
129133 const month = prependWithZeros ( monthValue , MONTH_POSITIONS )
130134 const year = prependWithZeros ( components [ yearIdx ] , YEAR_POSITIONS )
131- return `${ year } -${ month } -${ day } // `
135+ return `${ year } -${ month } -${ day } ${ SLASH_SEPARATOR } ${ SLASH_SEPARATOR } `
132136 }
133137}
134138
@@ -137,14 +141,18 @@ export const getNormalizedDate_yyyy_dd_mm_NormalizerFn = getNormalizedDate_Norma
137141export const getNormalizedDate_dd_Mmm_yyyy_NormalizerFn = getNormalizedDate_NormalizerFn_for ( '-' , 0 , 1 , 2 , MONTHS )
138142export const getNormalizedDate_Mmm_dd_yyyy_NormalizerFn = getNormalizedDate_NormalizerFn_for ( '-' , 1 , 0 , 2 , MONTHS )
139143
144+ const DateExtractor_orderModifier_earlier_than = '-'
145+ const DateExtractor_orderModifier_later_than = '+'
146+
140147const DateExtractor_yyyy_Www_mm_dd_Regex = / ( \d { 4 } ) - W ( \d { 1 , 2 } ) \( ( \d { 2 } ) - ( \d { 2 } ) \) /
141- const DateExtractor_yyyy_Www_Regex = / ( \d { 4 } ) - W ( \d { 1 , 2 } ) /
148+ const DateExtractor_yyyy_Www_Regex = / ( \d { 4 } ) - W ( \d { 1 , 2 } ) ( [ - + ] ? ) /
142149
143150// Matching groups
144151const YEAR_IDX = 1
145152const WEEK_IDX = 2
146153const MONTH_IDX = 3
147154const DAY_IDX = 4
155+ const RELATIVE_ORDER_IDX = 3 // For the yyyy-Www only: yyyy-Www> or yyyy-Www<
148156
149157const DECEMBER = 12
150158const JANUARY = 1
@@ -157,10 +165,19 @@ export function getNormalizedDate_NormalizerFn_yyyy_Www_mm_dd(consumeWeek: boole
157165 let yearNumber = Number . parseInt ( yearStr , 10 )
158166 let monthNumber : number
159167 let dayNumber : number
168+ let separator = SLASH_SEPARATOR // different values enforce relative > < order of same dates
169+ let useLastDayOfWeek : boolean = false
160170 if ( consumeWeek ) {
161171 const weekNumberStr = matches ! [ WEEK_IDX ]
162172 const weekNumber = Number . parseInt ( weekNumberStr , 10 )
163- const dateForWeek = getDateForWeekOfYear ( yearNumber , weekNumber , weeksISO )
173+ const orderModifier : string | undefined = matches ! [ RELATIVE_ORDER_IDX ]
174+ if ( orderModifier === DateExtractor_orderModifier_earlier_than ) {
175+ separator = EARLIER_THAN_SLASH_SEPARATOR
176+ } else if ( orderModifier === DateExtractor_orderModifier_later_than ) {
177+ separator = LATER_THAN_SLASH_SEPARATOR // Will also need to adjust the date to the last day of the week
178+ useLastDayOfWeek = true
179+ }
180+ const dateForWeek = getDateForWeekOfYear ( yearNumber , weekNumber , weeksISO , useLastDayOfWeek )
164181 monthNumber = dateForWeek . getMonth ( ) + 1 // 1 - 12
165182 dayNumber = dateForWeek . getDate ( ) // 1 - 31
166183 // Be careful with edge dates, which can belong to previous or next year
@@ -178,7 +195,10 @@ export function getNormalizedDate_NormalizerFn_yyyy_Www_mm_dd(consumeWeek: boole
178195 monthNumber = Number . parseInt ( matches ! [ MONTH_IDX ] , 10 )
179196 dayNumber = Number . parseInt ( matches ! [ DAY_IDX ] , 10 )
180197 }
181- return `${ prependWithZeros ( `${ yearNumber } ` , YEAR_POSITIONS ) } -${ prependWithZeros ( `${ monthNumber } ` , MONTH_POSITIONS ) } -${ prependWithZeros ( `${ dayNumber } ` , DAY_POSITIONS ) } //`
198+ return `${ prependWithZeros ( `${ yearNumber } ` , YEAR_POSITIONS ) } ` +
199+ `-${ prependWithZeros ( `${ monthNumber } ` , MONTH_POSITIONS ) } ` +
200+ `-${ prependWithZeros ( `${ dayNumber } ` , DAY_POSITIONS ) } ` +
201+ `${ separator } ${ SLASH_SEPARATOR } `
182202 }
183203}
184204
0 commit comments