Open Den368 opened 3 years ago
however, I noticed that if I put the Sugar.Date.getLocale("en").addFormat("the {edge} of the year {yyyy}");
code inside the function it works.
shouldn't the "addFormat" add the format to the global Sugar module?
found something intresting:
// @ts-ignore
console.log("Sugar.Date.getLocale():", DateUtils.Date.getLocale().compiledFormats);
output for the first run: the formats that been added via ".addFormat" are at the top of the ".compiledFormats" array. but in the second test the format regex moved to third place, and for the sentence "the end of the year 2022" it catches the first default format:
Sugar.Date.getLocale(): [
{
reg: /^ *(?:the)? ?(first day|first|beginning|last day|end|last) ?(Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sun|Mon|Tue|Wed|Thu|Fri|Sat|weekend)? ?(?:of|in) ?(last|the|this|next)? ?(day|week|month|year|days|weeks|months|years)? ?(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sept|Oct|Nov|Dec|Sep)?,? ?([-−+]?\d{4,6}|'\d{2})? *$/i,
to: [ 'edge', 'weekday', 'shift', 'unit', 'month', 'year' ]
},
Sugar.Date.getLocale().addFormat("the {edge} {weekday} of {shift} {unit} {month} {year}");
isn't working well.
by the regex it should catch the date. however it's not.
combination of {unit} {year}
in the format fails the format
something.ts
jest test file:
something.test.ts
when running the tests separately the
console.log("parsedComparisonDate:", parsedComparisonDate);
prints a correct value. however when running both tests theconsole.log("parsedComparisonDate:", parsedComparisonDate);
prints Invalid Date.Am I doing something wrong?