本文整理匯總了TypeScript中moment/moment.moment函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript moment函數的具體用法?TypeScript moment怎麽用?TypeScript moment使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了moment函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: transform
transform(timeEnd: string, timeStart: string): string {
if(!timeEnd || !timeStart) {
return 'unknown';
}
let start = moment(timeStart);
let end = moment(timeEnd);
let diff = end.diff(start, 'minutes');
if (diff < 1) {
return '< 1 minute';
} else if (diff == 1) {
return '1 minute';
} else if (diff < 60) {
return `${diff} minutes`;
}
diff = end.diff(start, 'hours');
if (diff === 1) {
return '1 hour';
} else if (diff < 24) {
return `${diff} hours`;
}
diff = end.diff(start, 'days');
if (diff === 1) {
return '1 day';
}
return `${diff} days`;
}
示例2: onModeChanged
onModeChanged(newMode: Number) {
this.calendarMode = newMode;
switch (this.calendarMode) {
case 1:
this.currentDate = this.currentDate.clone().startOf('month');
break;
case 2:
this.currentDate = this.currentDate.clone().startOf('week');
break;
case 3:
let firstMonthDiff = moment().diff(this.currentDate.startOf('week'), 'months');
let secondMonthDiff = moment().diff(this.currentDate.endOf('week'), 'months');
if (firstMonthDiff !== secondMonthDiff) {
if (firstMonthDiff < secondMonthDiff && firstMonthDiff >= 0) {
this.currentDate = moment().add(firstMonthDiff, 'months');
} else {
this.currentDate = moment().add(secondMonthDiff, 'months');
}
} else {
this.currentDate = this.currentDate.clone().startOf('month');
}
break;
default:
this.currentDate = this.currentDate.clone().startOf('month');
break;
}
}
示例3: constructor
constructor(req: IRequestState) {
this.id = req.id;
this.state = ViewRequestStates[req.status];
this.pickUpTime = moment(req.pickUpTime);
this.lineId = req.lineId;
this.acceptingBus = req.acceptingBus;
}
示例4: transform
public transform(timestampMicros: number): any {
if (!timestampMicros) {
return '';
}
moment.locale(I18n.language);
return moment(timestampMicros).format('LLL');
}
示例5: transform
transform(value: any): any {
if (isNaN(value)) {
return '';
}
return moment(new Date(value)).fromNow();
}
示例6: it
it('end date is invalid if it is in the future', () => {
expect(component.filterForm.get('endTime').valid).toBe(true);
component.filterForm.patchValue({
endTime: moment(new Date()).add(2, 'days').format(DEFAULT_TIMESTAMP_FORMAT)
});
expect(component.filterForm.get('endTime').valid).toBe(false);
});
示例7: isPublishedDate
export function isPublishedDate(start, end, format="YYYY-MM-DD")
{
let info = {result: false, publishedStart: "", publishedEnd: "", code: 0};
let s = void 0 === start ? null : moment(start);
let e = void 0 === end || !moment(end).isValid() ? null : moment(end);
//バリデーションチェック
if (null === s || !s.isValid()) { info.code = 1; return info;}
info.publishedStart = s.format(format);
if (null === e)
{
info.publishedEnd = null;
}
else
{
if (!e.isValid()) { info.code = 1; return info; }
if (s.isAfter(e)) { info.code = 2; return info; }
info.publishedEnd = e.format(format);
}
info.result = true;
return info;
}
示例8: parseDate
parseDate(inputString: string): Date {
return moment(inputString, "DD.MM.YYYY HH:mm").toDate();
}
示例9: formatDate
formatDate(inputDate: Date): string {
return moment(inputDate).format("DD.MM.YYYY HH:mm")
}
示例10: saveConference
saveConference(currentConference: Conference): Observable<Conference> {
currentConference.startDate = Moment(currentConference.startDateStr).utc().toDate();
currentConference.endDate = Moment(currentConference.endDateStr).utc().toDate();
return this.onSaveConference(currentConference);
}