Ideally, the output structure should emit a type field to show if pattern is really a date or not. Something like this:
typeFormatDateInfo={// new date type fieldtype: "date"|"time"|"datetime"|"none",clockType: 12|24,seconds: boolean,minutes: boolean,hours: boolean,day: boolean,month: boolean,year: boolean,}This has the benefit that:
- You don't have to call
isDateFormat to determine if something is a date beforehand. - You can pass the
info.time into a map of default patterns:
constISO_PATTERNS={date: "yyyy-mm-dd",time: "hh:mm:ss",datetime: "yyyy-mm-ddThh:mm:ss",none: "General",};// return an ISO formatted date, or a general formatted number, based on a cell format pattern:constinfo=getFormatDateInfo(pattern);constnormalizedPattern=ISO_PATTERNS[info.type];returnformat(normalizedPattern,value);
Alternatively, we might consider a isDate + granularity approach:
typeFormatDateInfo={// new "is a date or not" fielddate: boolean,// new granularity fieldgranularity: "year"|"month"|"day"|"hours"|"minutes"|"seconds"|"none",
...
}This does make it impossible to differentiate the "time" type though, so maybe it makes sense to do both.
Ideally, the output structure should emit a type field to show if pattern is really a date or not. Something like this:
This has the benefit that:
isDateFormatto determine if something is a date beforehand.info.timeinto a map of default patterns:Alternatively, we might consider a
isDate+granularityapproach:This does make it impossible to differentiate the "time" type though, so maybe it makes sense to do both.