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


TypeScript moment-timezone.utc函数代码示例

本文整理汇总了TypeScript中moment-timezone.utc函数的典型用法代码示例。如果您正苦于以下问题:TypeScript utc函数的具体用法?TypeScript utc怎么用?TypeScript utc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: transform

  transform(value: any, timezoneFrom?: string, timezoneTo?: string): string {
    if (typeof value === 'string') {
      value = parseInt(value, 10);

      if (isNaN(value)) {
        return '';
      }
    }

    if (typeof value !== 'number' && !(value instanceof Date) && !moment.isMoment(value)) {
      return '';
    }

    if (!timezoneFrom) {
      return typeof value === 'number'
        ? this.hourToString(value)
        : moment.utc(value).format('HH:mm');
    } else {
      timezoneTo = timezoneTo ? timezoneTo : moment.tz.guess();

      return moment
        .tz(
          typeof value === 'number'
            ? this.hourToString(value)
            : moment.utc(value).format('HH:mm'),
          'HH:mm',
          timezoneFrom
        )
        .tz(timezoneTo)
        .format('HH:mm');
    }
  }
开发者ID:Sirimangalo,项目名称:meditation-plus-angular,代码行数:32,代码来源:hour.pipe.ts

示例2: it

 it('should format date/moment objects correctly with timezones', () => {
   expect(pipe.transform(new Date('2014-06-01T16:16:00Z'), 'America/Toronto', 'America/Toronto')).toBe('16:16');
   expect(pipe.transform(new Date('2014-06-01T07:00:00Z'), 'America/Toronto', 'Europe/Berlin')).toBe('13:00');
   expect(pipe.transform(moment('2014-06-01T07:00:00Z'), 'America/Toronto', 'Europe/Berlin')).toBe('13:00');
   expect(pipe.transform(moment.utc('2014-06-01T07:00:00Z'), 'America/Toronto', 'Europe/Berlin')).toBe('13:00');
   expect(pipe.transform(moment('2014-06-01T18:30:00Z'), 'America/Toronto', 'Europe/Berlin')).toBe('00:30');
   expect(pipe.transform(moment('2014-06-01T09:30:00Z'), 'America/Toronto', 'Europe/Berlin')).toBe('15:30');
 });
开发者ID:Sirimangalo,项目名称:meditation-plus-angular,代码行数:8,代码来源:hour.pipe.spec.ts

示例3: RegExp

	export const signupMember = (member: MemberInterface): Promise<any> =>

		MemberModel.findOneAndUpdate(
			{
				firstname: { $in: new RegExp(`^${member.firstname}$`, 'i') },
				familyname: { $in: new RegExp(`^${member.familyname}$`, 'i') },
				emailaddress: { $in: new RegExp(`^${member.emailaddress}$`, 'i') },
				postcode: { $in: new RegExp(`^${member.postcode}$`, 'i') },
				dob: { $eq: moment.utc(member.dob) }
			},
			{
				password: bcrypt.hashSync(member.password)
			});
开发者ID:roderickmonk,项目名称:rod-monk-sample-repo-ng2,代码行数:13,代码来源:DB.ts

示例4: catch

export const formatDate = (date: string, options: FormatDateOptions = {}): string | null => {
  let time;
  try {
    // Unknown error was causing this to crash in rare situations.
    time = moment.utc(date).tz(options.timezone || 'GMT');
  }
  catch(e) {
    // Better to return a blank date than an error or incorrect information.
    reportException(e);
    return null;
  }
  const formattedTime = shouldHumanize(time, options.humanizeCutoff)
    ? time.fromNow()
    : time.format(options.format || ISO_FORMAT)
    return formattedTime;
};
开发者ID:displague,项目名称:manager,代码行数:16,代码来源:formatDate.ts

示例5: pathOr

export const formatDate = (
  date: string,
  options: FormatDateOptions = {}
): string => {
  let time;

  /** get the timezone from redux and use it as the moment timezone */
  const reduxProfile = store.getState().__resources.profile;
  const userTimezone = pathOr('GMT', ['data', 'timezone'], reduxProfile);

  try {
    // Unknown error was causing this to crash in rare situations.
    time = moment.utc(date).tz(userTimezone);
  } catch (e) {
    // Better to return a blank date than an error or incorrect information.
    reportException(e);
    return 'Error getting datetime';
  }
  const formattedTime = shouldHumanize(time, options.humanizeCutoff)
    ? time.fromNow()
    : time.format(options.format || ISO_FORMAT);
  return formattedTime;
};
开发者ID:linode,项目名称:manager,代码行数:23,代码来源:formatDate.ts

示例6: showTop


//.........这里部分代码省略.........
        }
        sorted = _.orderBy(users, 'value', 'desc');
        break;
      case TYPE.POINTS:
        if (!global.systems.points.isEnabled()) {
          return;
        }

        sorted = [];
        for (const user of (await global.db.engine.find('users.points', { _sort: 'points', _sum: 'points', _total, _group: 'id' }))) {
          sorted.push({ username: await global.users.getNameById(user._id), value: user.points });
        }
        message = global.translate('systems.top.points').replace(/\$amount/g, 10);
        break;
      case TYPE.MESSAGES:
        sorted = [];
        for (const user of (await global.db.engine.find('users.messages', { _sort: 'messages', _sum: 'messages', _total, _group: 'id' }))) {
          sorted.push({ username: await global.users.getNameById(user._id), value: user.messages });
        }
        message = global.translate('systems.top.messages').replace(/\$amount/g, 10);
        break;
      case TYPE.FOLLOWAGE:
        sorted = [];
        for (const user of (await global.db.engine.find('users', { is: { follower: true }, _sort: '-time.follow', _total }))) {
          sorted.push({ username: user.username, value: user.time.follow });
        }
        message = global.translate('systems.top.followage').replace(/\$amount/g, 10);
        break;
      case TYPE.SUBAGE:
        sorted = [];
        for (const user of (await global.db.engine.find('users', { is: { subscriber: true }, _sort: '-time.subscribed_at', _total }))) {
          sorted.push({ username: user.username, value: user.time.subscribed_at });
        }
        message = global.translate('systems.top.subage').replace(/\$amount/g, 10);
        break;
      case TYPE.BITS:
        sorted = [];
        for (const user of (await global.db.engine.find('users.bits', { _sort: 'amount', _sum: 'amount', _total, _group: 'id' }))) {
          sorted.push({ username: await global.users.getNameById(user._id), value: user.amount });
        }
        message = global.translate('systems.top.bits').replace(/\$amount/g, 10);
        break;
      case TYPE.GIFTS:
        sorted = [];
        for (const user of (await global.db.engine.find('users', { _sort: 'custom.subgiftCount', _total }))) {
          sorted.push({ username: user.username, value: user.custom.subgiftCount });
        }
        message = global.translate('systems.top.gifts').replace(/\$amount/g, 10);
        break;
    }

    if (sorted.length > 0) {
      // remove ignored users
      const ignored: string[] = [];
      for (const user of sorted) {
        if (isIgnored(user.username)) {
          ignored.push(user.username);
        }
      }

      _.remove(sorted, (o) => _.includes(ignored, o.username));
      // remove broadcaster and bot accounts
      _.remove(sorted, (o) => _.includes([getChannel(), global.oauth.settings.bot.username.toLowerCase()], o.username));
      sorted = _.chunk(sorted, 10)[0];

      for (const user of sorted) {
        message += (i + 1) + '. ' + (global.tmi.settings.chat.showWithAt ? '@' : '') + (user.username || 'unknown') + ' - ';
        switch (type) {
          case TYPE.TIME:
            message += (user.value / 1000 / 60 / 60).toFixed(1) + 'h';
            break;
          case TYPE.TIPS:
            message += user.value.toFixed(2) + global.currency.symbol(global.currency.settings.currency.mainCurrency);
            break;
          case TYPE.POINTS:
            message += user.value + ' ' + await global.systems.points.getPointsName(user.value);
            break;
          case TYPE.MESSAGES:
          case TYPE.BITS:
          case TYPE.GIFTS:
            message += String(user.value);
            break;
          case TYPE.FOLLOWAGE:
          case TYPE.SUBAGE:
            message += `${moment.utc(user.value).format('L')} (${moment.utc(user.value).fromNow()})`;
            break;
        }
        if (i + 1 < 10 && !_.isNil(sorted[i + 1])) {
          message += ', ';
        }
        i++;
      }
    } else {
      message += 'no data available';
    }
    if (__DEBUG__) {
      global.log.debug(message);
    }
    sendMessage(message, opts.sender);
  }
开发者ID:sogehige,项目名称:SogeBot,代码行数:101,代码来源:top.ts


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