本文整理汇总了TypeScript中chronoshift.Timezone类的典型用法代码示例。如果您正苦于以下问题:TypeScript Timezone类的具体用法?TypeScript Timezone怎么用?TypeScript Timezone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timezone类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: formatStartEnd
export function formatStartEnd(start: Date, end: Date, timezone: Timezone): string {
var startWallTime = WallTime.UTCToWallTime(start, timezone.toString());
var endWallTime = WallTime.UTCToWallTime(end, timezone.toString());
var endShiftWallTime = WallTime.UTCToWallTime(new Date(end.valueOf() - 1), timezone.toString());
var formatted: string;
if (startWallTime.getFullYear() !== endShiftWallTime.getFullYear()) {
formatted = [formatWithYear(startWallTime), formatWithYear(endShiftWallTime)].join(JOIN);
} else {
if (startWallTime.getMonth() !== endShiftWallTime.getMonth() || startWallTime.getDate() !== endShiftWallTime.getDate()) {
formatted = [formatWithoutYear(startWallTime), formatWithYear(endShiftWallTime)].join(JOIN);
} else {
formatted = formatWithYear(startWallTime);
}
}
if (startWallTime.getHours() || endWallTime.getHours()) {
var timeString: string;
if (startWallTime.getHours() !== endShiftWallTime.getHours()) {
timeString = [formatTimeOfDay(startWallTime), formatTimeOfDay(endShiftWallTime)].join(JOIN);
} else {
timeString = formatTimeOfDay(startWallTime);
}
formatted += ' ' + timeString.toLowerCase();
}
return formatted;
}
示例2: getWallTimeString
export function getWallTimeString(date: Date, timezone: Timezone, includeTime?: boolean, delimiter?: string): string {
const wallTimeISOString = wallTimeHelper(WallTime.UTCToWallTime(date, timezone.toString())).toISOString();
if (includeTime) {
return wallTimeISOString.replace(/(\.\d\d\d)?Z?$/, '').replace('T', delimiter || ', ');
}
return wallTimeISOString.replace( /:\d\d(\.\d\d\d)?Z?$/, '').split('T')[0];
}
示例3: 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());
}
}
示例4: formatTimeRange
export function formatTimeRange(timeRange: TimeRange, timezone: Timezone, displayYear: DisplayYear): string {
var { start, end } = timeRange;
var startWallTime = WallTime.UTCToWallTime(start, timezone.toString());
var endWallTime = WallTime.UTCToWallTime(end, timezone.toString());
var endWallTimeInclusive = getEndWallTimeInclusive(end, timezone);
var showingYear = true;
var formatted: string;
if (startWallTime.getFullYear() !== endWallTimeInclusive.getFullYear()) {
formatted = [FORMAT_WITH_YEAR(startWallTime), FORMAT_WITH_YEAR(endWallTimeInclusive)].join(' - ');
} else {
showingYear = displayYear === DisplayYear.ALWAYS || (displayYear === DisplayYear.IF_DIFF && !isCurrentYear(endWallTimeInclusive.getFullYear(), timezone));
var fmt = showingYear ? FORMAT_WITH_YEAR : FORMAT_WITHOUT_YEAR;
if (startWallTime.getMonth() !== endWallTimeInclusive.getMonth() || startWallTime.getDate() !== endWallTimeInclusive.getDate()) {
formatted = [FORMAT_WITHOUT_YEAR(startWallTime), fmt(endWallTimeInclusive)].join(' - ');
} else {
formatted = fmt(startWallTime);
}
}
if (startWallTime.getHours() || startWallTime.getMinutes() || endWallTime.getHours() || endWallTime.getMinutes()) {
formatted += (showingYear ? ' ' : ', ');
var startTimeStr = formatTimeOfDay(startWallTime).toLowerCase();
var endTimeStr = formatTimeOfDay(endWallTime).toLowerCase();
if (startTimeStr === endTimeStr) {
formatted += startTimeStr;
} else {
if (startTimeStr.substr(-2) === endTimeStr.substr(-2)) {
startTimeStr = startTimeStr.substr(0, startTimeStr.length - 2);
}
formatted += [startTimeStr, endTimeStr].join('-');
}
}
return formatted;
}
示例5: monthToWeeks
export function monthToWeeks(firstDayOfMonth: Date, timezone: Timezone, locale: Locale): Date[][] {
const weeks: Date[][] = [];
const firstDayNextMonth = month.shift(firstDayOfMonth, timezone, 1);
let week: Date[] = [];
let currentPointer = day.floor(firstDayOfMonth, timezone);
while (currentPointer < firstDayNextMonth) {
var wallTime = WallTime.UTCToWallTime(currentPointer, timezone.toString());
if ((wallTime.getDay() === locale.weekStart || 0) && week.length > 0) {
weeks.push(week);
week = [];
}
week.push(currentPointer);
currentPointer = day.shift(currentPointer, timezone, 1);
}
// push last week
if (week.length > 0) weeks.push(week);
return weeks;
}
示例6: getEndWallTimeInclusive
export function getEndWallTimeInclusive(exclusiveEnd: Date, timezone: Timezone) {
return WallTime.UTCToWallTime(exclusiveToInclusiveEnd(exclusiveEnd), timezone.toString());
}
示例7: isCurrentYear
function isCurrentYear(year: number, timezone: Timezone): boolean {
var nowWallTime = WallTime.UTCToWallTime(new Date(), timezone.toString());
return nowWallTime.getFullYear() === year;
}
示例8: getWallTimeMonthWithYear
export function getWallTimeMonthWithYear(date: Date, timezone: Timezone) {
return FORMAT_FULL_MONTH_WITH_YEAR(WallTime.UTCToWallTime(date, timezone.toString()));
}
示例9: getWallTimeDay
export function getWallTimeDay(date: Date, timezone: Timezone) {
return WallTime.UTCToWallTime(date, timezone.toString()).getDate();
}