當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript luxon.DateTime類代碼示例

本文整理匯總了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);
  }
}
開發者ID:ha4us,項目名稱:ha4us.old,代碼行數:7,代碼來源:templates.ts

示例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');
 });
開發者ID:BoykoAlex,項目名稱:spring-cloud-dataflow-ui,代碼行數:32,代碼來源:job-execution.model.spec.ts

示例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;
 }
開發者ID:BoykoAlex,項目名稱:spring-cloud-dataflow-ui,代碼行數:26,代碼來源:job-execution.model.ts

示例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()
}
開發者ID:jkbrzt,項目名稱:rrule,代碼行數:12,代碼來源:utils.ts

示例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);
 }
開發者ID:BoykoAlex,項目名稱:spring-cloud-dataflow-ui,代碼行數:13,代碼來源:task-execution.ts

示例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';
   }
 }
開發者ID:BoykoAlex,項目名稱:spring-cloud-dataflow-ui,代碼行數:13,代碼來源:dataflow-date-time.pipe.ts

示例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()
  })
開發者ID:jkbrzt,項目名稱:rrule,代碼行數:13,代碼來源:datewithzone.test.ts

示例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()
    })
開發者ID:jkbrzt,項目名稱:rrule,代碼行數:31,代碼來源:rruleset.test.ts

示例9: timestampToArray

 timestampToArray(ms: number): number[] {
   return luxonToArray(
     LuxonDateTime.fromMillis(ms, {
       zone: this.timeZoneName
     })
   )
 }
開發者ID:BorjaPintos,項目名稱:fullcalendar,代碼行數:7,代碼來源:main.ts

示例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);
    }
  }
開發者ID:sogehige,項目名稱:SogeBot,代碼行數:32,代碼來源:userinfo.ts


注:本文中的luxon.DateTime類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。