(
// Note: The result based on `isUTC` are totally different, which can not be just simply
// substituted by the result without `isUTC`. So we make the param `isUTC` mandatory.
time: unknown, template: string, isUTC: boolean, lang?: string | Model<LocaleOption>
)
| 275 | } |
| 276 | |
| 277 | export function format( |
| 278 | // Note: The result based on `isUTC` are totally different, which can not be just simply |
| 279 | // substituted by the result without `isUTC`. So we make the param `isUTC` mandatory. |
| 280 | time: unknown, template: string, isUTC: boolean, lang?: string | Model<LocaleOption> |
| 281 | ): string { |
| 282 | const date = numberUtil.parseDate(time); |
| 283 | const y = date[fullYearGetterName(isUTC)](); |
| 284 | const M = date[monthGetterName(isUTC)]() + 1; |
| 285 | const q = Math.floor((M - 1) / 3) + 1; |
| 286 | const d = date[dateGetterName(isUTC)](); |
| 287 | const e = date['get' + (isUTC ? 'UTC' : '') + 'Day' as 'getDay' | 'getUTCDay'](); |
| 288 | const H = date[hoursGetterName(isUTC)](); |
| 289 | const h = (H - 1) % 12 + 1; |
| 290 | const m = date[minutesGetterName(isUTC)](); |
| 291 | const s = date[secondsGetterName(isUTC)](); |
| 292 | const S = date[millisecondsGetterName(isUTC)](); |
| 293 | const a = H >= 12 ? 'pm' : 'am'; |
| 294 | const A = a.toUpperCase(); |
| 295 | |
| 296 | const localeModel = lang instanceof Model ? lang |
| 297 | : getLocaleModel(lang || SYSTEM_LANG) || getDefaultLocaleModel(); |
| 298 | const timeModel = localeModel.getModel('time'); |
| 299 | const month = timeModel.get('month'); |
| 300 | const monthAbbr = timeModel.get('monthAbbr'); |
| 301 | const dayOfWeek = timeModel.get('dayOfWeek'); |
| 302 | const dayOfWeekAbbr = timeModel.get('dayOfWeekAbbr'); |
| 303 | |
| 304 | return (template || '') |
| 305 | .replace(/{a}/g, a + '') |
| 306 | .replace(/{A}/g, A + '') |
| 307 | .replace(/{yyyy}/g, y + '') |
| 308 | .replace(/{yy}/g, pad(y % 100 + '', 2)) |
| 309 | .replace(/{Q}/g, q + '') |
| 310 | .replace(/{MMMM}/g, month[M - 1]) |
| 311 | .replace(/{MMM}/g, monthAbbr[M - 1]) |
| 312 | .replace(/{MM}/g, pad(M, 2)) |
| 313 | .replace(/{M}/g, M + '') |
| 314 | .replace(/{dd}/g, pad(d, 2)) |
| 315 | .replace(/{d}/g, d + '') |
| 316 | .replace(/{eeee}/g, dayOfWeek[e]) |
| 317 | .replace(/{ee}/g, dayOfWeekAbbr[e]) |
| 318 | .replace(/{e}/g, e + '') |
| 319 | .replace(/{HH}/g, pad(H, 2)) |
| 320 | .replace(/{H}/g, H + '') |
| 321 | .replace(/{hh}/g, pad(h + '', 2)) |
| 322 | .replace(/{h}/g, h + '') |
| 323 | .replace(/{mm}/g, pad(m, 2)) |
| 324 | .replace(/{m}/g, m + '') |
| 325 | .replace(/{ss}/g, pad(s, 2)) |
| 326 | .replace(/{s}/g, s + '') |
| 327 | .replace(/{SSS}/g, pad(S, 3)) |
| 328 | .replace(/{S}/g, S + ''); |
| 329 | } |
| 330 | |
| 331 | export function leveledFormat( |
| 332 | tick: ScaleTick, |
no test coverage detected