本文整理匯總了TypeScript中luxon.DateTime類的典型用法代碼示例。如果您正苦於以下問題:TypeScript DateTime類的具體用法?TypeScript DateTime怎麽用?TypeScript DateTime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DateTime類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: convertDate
function convertDate(date: string | Date): DateTime {
if (typeof date === 'string') {
return DateTime.fromISO(date);
} else {
return DateTime.fromJSDate(date);
}
}
示例2: it
it('should parse the JSON into a JobExecution model with step execution', () => {
const jobExecution = JobExecution.fromJSON(JOBS_EXECUTIONS_1);
expect(jobExecution.name).toBe('job1');
expect(jobExecution.startTime.toISO()).toBe(DateTime.fromISO('2017-08-11T06:15:50.027Z').toISO());
expect(jobExecution.endTime.toISO()).toBe(DateTime.fromISO('2017-08-11T06:15:50.067Z').toISO());
expect(jobExecution.stepExecutionCount).toBe(1);
expect(jobExecution.status).toBe('COMPLETED');
expect(jobExecution.exitCode).toBe('COMPLETED');
expect(jobExecution.exitMessage).toBe('');
expect(jobExecution.jobExecutionId).toBe(1);
expect(jobExecution.taskExecutionId).toBe(2);
expect(jobExecution.jobInstanceId).toBe(1);
expect(jobExecution.jobParametersString).toBe('--spring.cloud.task.executionid=2');
expect(jobExecution.restartable).toBe(false);
expect(jobExecution.abandonable).toBe(false);
expect(jobExecution.stoppable).toBe(false);
expect(jobExecution.defined).toBe(true);
expect(jobExecution.stepExecutions[0].id.toString()).toBe('1');
expect(jobExecution.stepExecutions[0].name).toBe('job1step1');
expect(jobExecution.stepExecutions[0].readCount).toBe(0);
expect(jobExecution.stepExecutions[0].writeCount).toBe(0);
expect(jobExecution.stepExecutions[0].commitCount).toBe(1);
expect(jobExecution.stepExecutions[0].rollbackCount).toBe(0);
expect(jobExecution.stepExecutions[0].readSkipCount).toBe(0);
expect(jobExecution.stepExecutions[0].processSkipCount).toBe(0);
expect(jobExecution.stepExecutions[0].writeSkipCount).toBe(0);
expect(jobExecution.stepExecutions[0].filterCount).toBe(0);
expect(jobExecution.stepExecutions[0].skipCount).toBe(0);
expect(jobExecution.stepExecutions[0].startTime.toISO()).toBe(DateTime.fromISO('2017-08-11T06:15:50.046Z').toISO());
expect(jobExecution.stepExecutions[0].endTime.toISO()).toBe(DateTime.fromISO('2017-08-11T06:15:50.064Z').toISO());
expect(jobExecution.stepExecutions[0].status).toBe('COMPLETED');
});
示例3: fromJSON
static fromJSON(input): JobExecution {
const jobExecution: JobExecution = new JobExecution();
jobExecution.name = input.name;
jobExecution.startTime = DateTime.fromISO(input.jobExecution.startTime);
jobExecution.stepExecutionCount = input.stepExecutionCount;
jobExecution.status = input.jobExecution.status;
jobExecution.jobExecutionId = input.jobExecution.id;
jobExecution.taskExecutionId = input.taskExecutionId;
jobExecution.jobInstanceId = input.jobExecution.jobInstance.id;
jobExecution.restartable = input.restartable;
jobExecution.abandonable = input.abandonable;
jobExecution.stoppable = input.stoppable;
jobExecution.defined = input.defined;
if (input.jobExecution.endTime) {
jobExecution.endTime = DateTime.fromISO(input.jobExecution.endTime);
}
if (input.jobExecution.exitStatus) {
jobExecution.exitCode = input.jobExecution.exitStatus.exitCode;
jobExecution.exitMessage = input.jobExecution.exitStatus.exitDescription;
}
jobExecution.jobParametersString = input.jobParametersString;
if (input.jobExecution.stepExecutions) {
jobExecution.stepExecutions = input.jobExecution.stepExecutions.map(StepExecution.fromJSON);
}
return jobExecution;
}
示例4: expectedDate
export function expectedDate(startDate: DateTime, currentLocalDate: DateTime, targetZone: string): Date {
const targetOffset = startDate.setZone(targetZone).offset
const { zoneName: systemZone } = currentLocalDate
const {
offset: systemOffset,
} = startDate.setZone(systemZone)
const netOffset = targetOffset - systemOffset
const hours = -((netOffset / 60) % 24)
const minutes = -(netOffset % 60)
return startDate.plus({ hours, minutes }).toJSDate()
}
示例5: fromJSON
static fromJSON(jsonItem): TaskExecution {
return new TaskExecution(
jsonItem.executionId,
jsonItem.exitCode,
jsonItem.taskName,
jsonItem.startTime ? DateTime.fromISO(jsonItem.startTime) : null,
jsonItem.endTime ? DateTime.fromISO(jsonItem.endTime) : null,
jsonItem.exitMessage,
jsonItem.arguments,
jsonItem.jobExecutionIds,
jsonItem.errorMessage,
jsonItem.externalExecutionId);
}
示例6: transform
transform(value: string | DateTime, format: string = null): string {
let m: DateTime;
if (value instanceof DateTime) {
m = value;
} else {
m = DateTime.fromISO(value as string);
}
if (m.isValid) {
return m.toFormat(format != null ? format : DateTimeUtils.DEFAULT);
} else {
return 'N/A';
}
}
示例7: it
it('returns the date in the correct zone when given', () => {
const targetZone = 'America/New_York'
const currentLocalDate = DateTime.local(2000, 2, 6, 1, 0, 0)
setMockDate(currentLocalDate.toJSDate())
const d = DateTime.fromISO('20101005T110000').toJSDate()
const dt = new DateWithZone(d, targetZone)
expect(dt.rezonedDate()).to.deep.equal(
expectedDate(DateTime.fromISO('20101005T110000'), currentLocalDate, targetZone)
)
resetMockDate()
})
示例8: it
it('generates correcty zoned recurrences when a tzid is present', () => {
const targetZone = 'America/New_York'
const currentLocalDate = DateTime.local(2000, 2, 6, 11, 0, 0)
setMockDate(currentLocalDate.toJSDate())
const set = new RRuleSet()
set.rrule(new RRule({
freq: RRule.YEARLY,
count: 4,
dtstart: DateTime.fromISO('20000101T090000').toJSDate(),
tzid: targetZone
}))
set.exdate(
DateTime.fromISO('20010101T090000').toJSDate(),
)
set.rdate(
DateTime.fromISO('20020301T090000').toJSDate(),
)
expect(set.all()).to.deep.equal([
expectedDate(DateTime.fromISO('20000101T090000'), currentLocalDate, targetZone),
expectedDate(DateTime.fromISO('20020101T090000'), currentLocalDate, targetZone),
expectedDate(DateTime.fromISO('20020301T090000'), currentLocalDate, targetZone),
expectedDate(DateTime.fromISO('20030101T090000'), currentLocalDate, targetZone),
])
resetMockDate()
})
示例9: timestampToArray
timestampToArray(ms: number): number[] {
return luxonToArray(
LuxonDateTime.fromMillis(ms, {
zone: this.timeZoneName
})
)
}
示例10: age
protected async age(opts: CommandOptions) {
let username;
const parsed = opts.parameters.match(/([^@]\S*)/g);
if (_.isNil(parsed)) {
username = opts.sender.username;
} else {
username = parsed[0].toLowerCase();
}
const user = await global.users.getByName(username);
if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.created_at)) {
sendMessage(prepare('age.failed', { username }), opts.sender);
} else {
const units: string[] = ['years', 'months', 'days', 'hours', 'minutes'];
const diff = DateTime.fromMillis(new Date(user.time.created_at).getTime()).diffNow(['years', 'months', 'days', 'hours', 'minutes']);
const output: string[] = [];
for (const unit of units) {
if (diff[unit]) {
const v = -Number(diff[unit]).toFixed();
output.push(v + ' ' + getLocalizedName(v, 'core.' + unit));
}
}
if (output.length === 0) {
output.push(0 + ' ' + getLocalizedName(0, 'core.minutes'));
}
sendMessage(prepare('age.success.' + (opts.sender.username === username.toLowerCase() ? 'withoutUsername' : 'withUsername'), {
username,
diff: output.join(', '),
}), opts.sender);
}
}