本文整理汇总了TypeScript中chronoshift.Duration.toJS方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Duration.toJS方法的具体用法?TypeScript Duration.toJS怎么用?TypeScript Duration.toJS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chronoshift.Duration
的用法示例。
在下文中一共展示了Duration.toJS方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: formatTimeBasedOnGranularity
export function formatTimeBasedOnGranularity(range: TimeRange, granularity: Duration, timezone: Timezone, locale: Locale): string {
const wallTimeStart = WallTime.UTCToWallTime(range.start, timezone.toString());
const year = wallTimeStart.getFullYear();
const month = wallTimeStart.getMonth();
const day = wallTimeStart.getDate();
const hour = wallTimeStart.getHours();
const minute = wallTimeStart.getMinutes();
const second = wallTimeStart.getSeconds();
const monthString = locale.shortMonths[month];
const hourToTwelve = hour % 12 === 0 ? 12 : hour % 12;
const amPm = (hour / 12) >= 1 ? 'pm' : 'am';
var granularityString = granularity.toJS();
var unit = granularityString.substring(granularityString.length - 1);
switch (unit) {
case 'S':
return `${monthString} ${day}, ${pad(hour)}:${pad(minute)}:${pad(second)}`;
case 'M':
var prefix = granularityString.substring(0, 2);
return prefix === "PT" ? `${monthString} ${day}, ${hourToTwelve}:${pad(minute)}${amPm}` : `${monthString}, ${year}`;
case 'H':
return `${monthString} ${day}, ${year}, ${hourToTwelve}${amPm}`;
case 'D':
return `${monthString} ${day}, ${year}`;
case 'W':
return `${formatTimeRange(range, timezone, DisplayYear.ALWAYS)}`;
default:
return cleanISOString(wallTimeHelper(wallTimeStart).toISOString());
}
}