本文整理汇总了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);
}