当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript DateTime.fromMillis方法代码示例

本文整理汇总了TypeScript中luxon.DateTime.fromMillis方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DateTime.fromMillis方法的具体用法?TypeScript DateTime.fromMillis怎么用?TypeScript DateTime.fromMillis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在luxon.DateTime的用法示例。


在下文中一共展示了DateTime.fromMillis方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例2: timestampToArray

 timestampToArray(ms: number): number[] {
   return luxonToArray(
     LuxonDateTime.fromMillis(ms, {
       zone: this.timeZoneName
     })
   )
 }
开发者ID:BorjaPintos,项目名称:fullcalendar,代码行数:7,代码来源:main.ts

示例3: timestamp

export function timestamp(input: any) {
  if (!isInputValid(input)) {
    return '-';
  }
  const tz = SETTINGS.feature.displayTimestampsInUserLocalTime ? undefined : SETTINGS.defaultTimeZone;
  const thisMoment = DateTime.fromMillis(parseInt(input, 10), { zone: tz });
  return thisMoment.isValid ? thisMoment.toFormat('yyyy-MM-dd HH:mm:ss ZZZZ') : '-';
}
开发者ID:emjburns,项目名称:deck,代码行数:8,代码来源:timeFormatters.ts

示例4: reminder

  private async reminder() {
    if (!this.cleanedUpOnStart) {
      this.cleanedUpOnStart = true;
      this.settings._.closingAt = 0;
    } else if (this.settings._.closingAt !== 0) {
      const when = DateTime.fromMillis(this.settings._.closingAt, { locale: global.general.settings.lang });
      const lastRemindAtDiffMs = -(DateTime.fromMillis(this.settings._.lastRemindAt).diffNow().toObject().milliseconds || 0);

      const minutesToGo = when.diffNow(['minutes']).toObject().minutes || 0;
      const secondsToGo = round5(when.diffNow(['seconds']).toObject().seconds || 0);

      if (minutesToGo > 1) {
        // countdown every minute
        if (lastRemindAtDiffMs >= constants.MINUTE) {
          sendMessage(
            prepare('systems.scrim.countdown', {
              type: this.settings._.type,
              time: minutesToGo.toFixed(),
              unit: getLocalizedName(minutesToGo.toFixed(), 'core.minutes'),
            }),
            { username: getOwner() },
          );
          this.settings._.lastRemindAt = Date.now();
        }
      } else if (secondsToGo <= 60 && secondsToGo > 0) {
        // countdown every 15s
        if (lastRemindAtDiffMs >= 15 * constants.SECOND) {
          sendMessage(
            prepare('systems.scrim.countdown', {
              type: this.settings._.type,
              time: String(secondsToGo === 60 ? 1 : secondsToGo),
              unit: secondsToGo === 60 ? getLocalizedName(1, 'core.minutes') : getLocalizedName(secondsToGo, 'core.seconds'),
            }),
            { username: getOwner() },
          );
          this.settings._.lastRemindAt = Date.now();
        }
      } else {
        this.settings._.closingAt = 0;
        this.countdown();
      }
    }
  }
开发者ID:sogehige,项目名称:SogeBot,代码行数:43,代码来源:scrim.ts

示例5: relativeTime

export function relativeTime(input: any) {
  if (!isInputValid(input)) {
    return '-';
  }
  const now = Date.now();
  const inputNumber = parseInt(input, 10);
  const inFuture = inputNumber > now;
  const thisMoment = DateTime.fromMillis(inputNumber);
  const baseText = distanceInWordsToNow(thisMoment.toJSDate(), { includeSeconds: true });
  return thisMoment.isValid ? `${inFuture ? 'in ' : ''}${baseText}${inFuture ? '' : ' ago'}` : '-';
}
开发者ID:emjburns,项目名称:deck,代码行数:11,代码来源:timeFormatters.ts

示例6: subage

  protected async subage(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);
    const subCumulativeMonths = _.get(user, 'stats.subCumulativeMonths', undefined);
    const subStreak = _.get(user, 'stats.subStreak', undefined);
    const localePath = 'subage.' + (opts.sender.username === username.toLowerCase() ? 'successSameUsername' : 'success') + '.';

    if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.subscribed_at) || _.isNil(user.is.subscriber) || !user.is.subscriber) {
      sendMessage(prepare(localePath + (subCumulativeMonths ? 'notNow' : 'never'), {
        username,
        subCumulativeMonths,
        subCumulativeMonthsName: getLocalizedName(subCumulativeMonths || 0, 'core.months'),
      }), opts.sender);
    } else {
      const units: string[] = ['years', 'months', 'days', 'hours', 'minutes'];
      const diff = DateTime.fromMillis(user.time.subscribed_at).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(localePath + (subStreak ? 'timeWithSubStreak' : 'time'), {
        username,
        subCumulativeMonths,
        subCumulativeMonthsName: getLocalizedName(subCumulativeMonths || 0, 'core.months'),
        subStreak,
        subStreakName: getLocalizedName(subStreak || 0, 'core.months'),
        diff: output.join(', '),
      }), opts.sender);
    }
  }
开发者ID:sogehige,项目名称:SogeBot,代码行数:45,代码来源:userinfo.ts

示例7: lastseen

  protected async lastseen(opts: CommandOptions) {
    try {
      const parsed = opts.parameters.match(/^([\S]+)$/);
      if (parsed === null) {
        throw new Error();
      }

      const user = await global.users.getByName(parsed[0]);
      if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.message)) {
        sendMessage(global.translate('lastseen.success.never').replace(/\$username/g, parsed[0]), opts.sender);
      } else {
        const when = DateTime.fromMillis(user.time.message, { locale: global.general.settings.lang});
        sendMessage(global.translate('lastseen.success.time')
          .replace(/\$username/g, parsed[0])
          .replace(/\$when/g, when.toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS)), opts.sender);
      }
    } catch (e) {
      sendMessage(global.translate('lastseen.failed.parse'), opts.sender);
    }
  }
开发者ID:sogehige,项目名称:SogeBot,代码行数:20,代码来源:userinfo.ts

示例8: followage

  protected async followage(opts: CommandOptions) {
    let username;
    const parsed = opts.parameters.match(/([^@]\S*)/g);

    if (_.isNil(parsed)) {
      username = opts.sender.username;
    } else {
      username = parsed[0].toLowerCase();
    }

    const isFollowerUpdate = await global.api.isFollowerUpdate({
      id: opts.sender.userId,
    });
    debug('userinfo.followage', JSON.stringify(isFollowerUpdate));

    const user = await global.users.getByName(username);
    if (_.isNil(user) || _.isNil(user.time) || _.isNil(user.time.follow) || _.isNil(user.is.follower) || !user.is.follower) {
      sendMessage(prepare('followage.' + (opts.sender.username === username.toLowerCase() ? 'successSameUsername' : 'success') + '.never', { username }), opts.sender);
    } else {
      const units: string[] = ['years', 'months', 'days', 'hours', 'minutes'];
      const diff = DateTime.fromMillis(user.time.follow).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('followage.' + (opts.sender.username === username.toLowerCase() ? 'successSameUsername' : 'success') + '.time', {
          username,
          diff: output.join(', '),
        }), opts.sender);
    }
  }
开发者ID:sogehige,项目名称:SogeBot,代码行数:38,代码来源:userinfo.ts

示例9:

dt.set({ hour: 3 }).hour;

const f = { month: 'long', day: 'numeric' };
dt.setLocale('fr').toLocaleString(f);
dt.setLocale('en-GB').toLocaleString(f);
dt.setLocale('en-US').toLocaleString(f);

DateTime.fromObject({ zone: 'America/Los_Angeles' });
DateTime.local().setZone('America/Los_Angeles');

DateTime.utc(2017, 5, 15);
DateTime.utc();
DateTime.local().toUTC();
DateTime.utc().toLocal();

DateTime.fromMillis(1527780819458).toMillis();

/* Duration */
const dur = Duration.fromObject({ hours: 2, minutes: 7 });
dt.plus(dur);
dur.hours;
dur.minutes;
dur.seconds;

dur.as('seconds');
dur.toObject();
dur.toISO();

/* Interval */
const later = DateTime.local();
const i = Interval.fromDateTimes(now, later);
开发者ID:horiuchi,项目名称:DefinitelyTyped,代码行数:31,代码来源:luxon-tests.ts


注:本文中的luxon.DateTime.fromMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。