• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript moment.isMoment函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: describeTimeRange

export function describeTimeRange(range) {
  const option = rangeIndex[range.from.toString() + ' to ' + range.to.toString()];
  if (option) {
    return option.display;
  }

  if (moment.isMoment(range.from) && moment.isMoment(range.to)) {
    return formatDate(range.from) + ' to ' + formatDate(range.to);
  }

  if (moment.isMoment(range.from)) {
    const toMoment = dateMath.parse(range.to, true);
    return formatDate(range.from) + ' to ' + toMoment.fromNow();
  }

  if (moment.isMoment(range.to)) {
    const from = dateMath.parse(range.from, false);
    return from.fromNow() + ' to ' + formatDate(range.to);
  }

  if (range.to.toString() === 'now') {
    const res = describeTextRange(range.from);
    return res.display;
  }

  return range.from.toString() + ' to ' + range.to.toString();
}
开发者ID:gzq0616,项目名称:grafana,代码行数:27,代码来源:rangeutil.ts


示例2: function

 api.tasks.on.clean(scope, function (model) {
   if (model.est !== undefined && !moment.isMoment(model.est)) {
     model.est = moment(model.est)  // Earliest Start Time
   }
   if (model.lct !== undefined && !moment.isMoment(model.lct)) {
     model.lct = moment(model.lct)  // Latest Completion Time
   }
 })
开发者ID:angular-gantt,项目名称:angular-gantt,代码行数:8,代码来源:bounds.directive.ts


示例3: timeRangeForUrl

  timeRangeForUrl() {
    var range = this.timeRange().raw;

    if (moment.isMoment(range.from)) { range.from = range.from.valueOf().toString(); }
    if (moment.isMoment(range.to)) { range.to = range.to.valueOf().toString(); }

    return range;
  }
开发者ID:PaulMest,项目名称:grafana,代码行数:8,代码来源:time_srv.ts


示例4: it

    it("versions and groups should work with @Transform decorator too", () => {
        defaultMetadataStorage.clear();

        class User {

            id: number;

            name: string;

            @Type(() => Date)
            @Transform(value => moment(value), { since: 1, until: 2 })
            date: Date;

            @Type(() => Date)
            @Transform(value => value.toString(), { groups: ["user"] })
            lastVisitDate: Date;

        }

        let plainUser = {
            id: 1,
            name: "Johny Cage",
            date: new Date().valueOf(),
            lastVisitDate: new Date().valueOf()
        };

        const classedUser1 = plainToClass(User, plainUser);
        classedUser1.should.be.instanceOf(User);
        classedUser1.id.should.be.equal(1);
        classedUser1.name.should.be.equal("Johny Cage");
        moment.isMoment(classedUser1.date).should.be.true;

        const classedUser2 = plainToClass(User, plainUser, { version: 0.5 });
        classedUser2.should.be.instanceOf(User);
        classedUser2.id.should.be.equal(1);
        classedUser2.name.should.be.equal("Johny Cage");
        classedUser2.date.should.be.instanceof(Date);

        const classedUser3 = plainToClass(User, plainUser, { version: 1 });
        classedUser3.should.be.instanceOf(User);
        classedUser3.id.should.be.equal(1);
        classedUser3.name.should.be.equal("Johny Cage");
        moment.isMoment(classedUser3.date).should.be.true;

        const classedUser4 = plainToClass(User, plainUser, { version: 2 });
        classedUser4.should.be.instanceOf(User);
        classedUser4.id.should.be.equal(1);
        classedUser4.name.should.be.equal("Johny Cage");
        classedUser4.date.should.be.instanceof(Date);

        const classedUser5 = plainToClass(User, plainUser, { groups: ["user"] });
        classedUser5.should.be.instanceOf(User);
        classedUser5.id.should.be.equal(1);
        classedUser5.name.should.be.equal("Johny Cage");
        classedUser5.lastVisitDate.should.be.equal(new Date(plainUser.lastVisitDate).toString());
    });
开发者ID:MagnusCloudCorp,项目名称:class-transformer,代码行数:56,代码来源:custom-transform.spec.ts


示例5: function

      let taskCleanHandler = function (taskModel) {
        if (taskModel.id === $scope.task.model.id) {
          let model = $scope.section
          if (model.from !== undefined && !moment.isMoment(model.from)) {
            model.from = moment(model.from)
          }

          if (model.to !== undefined && !moment.isMoment(model.to)) {
            model.to = moment(model.to)
          }
        }
      }
开发者ID:angular-gantt,项目名称:angular-gantt,代码行数:12,代码来源:taskSection.directive.ts


示例6: timeRange

  timeRange() {
    // make copies if they are moment  (do not want to return out internal moment, because they are mutable!)
    var raw = {
      from: moment.isMoment(this.time.from) ? moment(this.time.from) : this.time.from,
      to: moment.isMoment(this.time.to) ? moment(this.time.to) : this.time.to,
    };

    return {
      from: dateMath.parse(raw.from, false),
      to: dateMath.parse(raw.to, true),
      raw: raw
    };
  }
开发者ID:housecream,项目名称:server,代码行数:13,代码来源:time_srv.ts


示例7: cleanTimespan

  cleanTimespan (model) {
    if (model.id === undefined) {
      model.id = GanttObjectModel.ganttUtils.randomUuid()
    }

    if (model.from !== undefined && !moment.isMoment(model.from)) {
      model.from = moment(model.from)
    }

    if (model.to !== undefined && !moment.isMoment(model.to)) {
      model.to = moment(model.to)
    }

    (this.api as any).timespans.raise.clean(model)
  }
开发者ID:angular-gantt,项目名称:angular-gantt,代码行数:15,代码来源:objectModel.factory.ts


示例8: timeRange

  timeRange(): TimeRange {
    // make copies if they are moment  (do not want to return out internal moment, because they are mutable!)
    const raw = {
      from: moment.isMoment(this.time.from) ? moment(this.time.from) : this.time.from,
      to: moment.isMoment(this.time.to) ? moment(this.time.to) : this.time.to,
    };

    const timezone = this.dashboard && this.dashboard.getTimezone();

    return {
      from: dateMath.parse(raw.from, false, timezone),
      to: dateMath.parse(raw.to, true, timezone),
      raw: raw,
    };
  }
开发者ID:CorpGlory,项目名称:grafana,代码行数:15,代码来源:TimeSrv.ts


示例9:

 const toUser = currentValue => {
   if (moment.isMoment(currentValue)) {
     return currentValue.format(format);
   } else {
     return currentValue;
   }
 };
开发者ID:ArcticSnowman,项目名称:grafana,代码行数:7,代码来源:validation.ts


示例10: parse

export function parse(text, roundUp?) {
  if (!text) { return undefined; }
  if (moment.isMoment(text)) { return text; }
  if (_.isDate(text)) { return moment(text); }

  var time;
  var mathString = '';
  var index;
  var parseString;

  if (text.substring(0, 3) === 'now') {
    time = moment();
    mathString = text.substring('now'.length);
  } else {
    index = text.indexOf('||');
    if (index === -1) {
      parseString = text;
      mathString = ''; // nothing else
    } else {
      parseString = text.substring(0, index);
      mathString = text.substring(index + 2);
    }
    // We're going to just require ISO8601 timestamps, k?
    time = moment(parseString);
  }

  if (!mathString.length) {
    return time;
  }

  return parseDateMath(mathString, time, roundUp);
}
开发者ID:eddawley,项目名称:grafana,代码行数:32,代码来源:datemath.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript moment.locale函数代码示例发布时间:2022-05-25
下一篇:
TypeScript moment.isDuration函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap