How to use moment - 10 common examples

To help you get started, we’ve selected a few moment examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / moment_v2.x.x / test_moment-v2.js View on Github external
it('is invalid to use special, undocumented formats', () => {
    // The following cases do generate valid moment objects, but this
    // seems to be an undocumented API. If the moment project decides to
    // document some of these APIs, then the types can be changed.

    // $ExpectError
    moment.parseZone(new Date());
    // $ExpectError
    moment.parseZone(moment());
    // $ExpectError
    moment.parseZone({ hour: 15, minute: 10 });
    // $ExpectError
    moment.parseZone(1318781876406);
    // $ExpectError
    moment.parseZone([2015, 0]);
  });
});
github choerodon / test-manager-service / react / src / app / testManager / store / project / TestPlan / TestPlanStore.js View on Github external
if (!versionId && !cycleId && children.length > 0) {
        // 版本 规划中
        let stepChildren = [];
        children.forEach((child) => {
          stepChildren = [...stepChildren, ...child.children];
        });
        // 进行过滤,防止时间为空
        const starts = stepChildren.filter(child => child.fromDate && child.toDate).map(child => moment(child.fromDate));
        const ends = stepChildren.filter(child => child.fromDate && child.toDate).map(child => moment(child.toDate));
        if (starts.length > 0 && ends.length > 0) {
          times.push({
            ...node,
            // children, 不需要编辑,不用限制时间的选择,所有不用传children
            type: 'topversion',
            start: moment.min(starts),
            end: moment.max(ends),
          });
        }
      } else if (versionId && !cycleId && children.length > 0) {
        // 版本 0.1.1
        // console.log(children);
        const starts = children.filter(child => child.fromDate && child.toDate).map(child => moment(child.fromDate));
        const ends = children.filter(child => child.fromDate && child.toDate).map(child => moment(child.toDate));
        if (starts.length > 0 && ends.length > 0) {
          times.push({
            ...node,
            // children,
            type: 'version',
            start: moment.min(starts),
            end: moment.max(ends),
          });
github flow-typed / flow-typed / definitions / npm / moment_v2.x.x / test_moment-v2.js View on Github external
moment.utc('2015-01-01', true);

  moment.utc({ hour: 15, minute: 10 });

  // $ExpectError only string values can have formatting parameters
  moment.utc([2015, 0], "MM-DD-YYYY");
  // $ExpectError
  moment.utc([2015, 0], "MM-DD-YYYY", true);
  // $ExpectError
  moment.utc([2015, 0], moment.ISO_8601);
  // $ExpectError
  moment.utc({ hour: 15, minute: 10 }, "MM-DD-YYYY");

  // Special formatting
  moment.utc("2010-01-01T05:06:07", moment.ISO_8601);
  moment.utc("2010-01-01T05:06:07", ["YYYY", moment.ISO_8601]);
  moment.utc(new Date());
  moment.utc(moment());

  // null and undefined allowed as per moment TypeScript definitions
  // https://github.com/moment/moment/blob/2.22.2/moment.d.ts#L400
  // https://github.com/moment/moment/blob/2.22.2/moment.d.ts#L622
  moment.utc(null);
  moment.utc(undefined);
});
github dutu / cryptox / test / shared / getBalance.js View on Github external
publicCryptox[method](options, function (err, result) {
            expect(result).to.be.jsonSchema(schema.errorResult);
            expect(moment(result.timestamp, moment.ISO_8601).isValid()).to.be.equal(true); // to be a valid ISO 8601 date
            done();
        });
    });
github Azure / autorest.typescript / test / vanilla / dist / Expected / AcceptanceTests / BodyComplex / operations / primitive.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            let client = this.client;
            let field = (options && options.field !== undefined) ? options.field : undefined;
            // Validate
            try {
                if (field && !moment.isDuration(field)) {
                    throw new Error('field must be of type moment.duration.');
                }
            }
            catch (error) {
                return Promise.reject(error);
            }
            let complexBody;
            if (field !== null && field !== undefined) {
                complexBody = {};
                complexBody.field = field;
            }
            // Construct URL
            let baseUrl = this.client.baseUri;
            let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'complex/primitive/duration';
            // Create HTTP transport objects
            let httpRequest = new WebResource();
github DominikAngerer / vue-heatmap / src / calendar-heatmap.js View on Github external
init() {
  // defaults
  let width = 750
  let height = 110
  let legendWidth = 150
  let selector = '.vuejs-heatmap'
  let SQUARE_LENGTH = 11
  let SQUARE_PADDING = 2
  let MONTH_LABEL_PADDING = 6
  let now = moment().endOf('day').toDate()
  let yearAgo = moment().startOf('day').subtract(1, 'year').toDate()
  let startDate = null
  let data = []
  let max = null
  let colorRange = ['#D8E6E7', '#218380']
  let tooltipEnabled = true
  let tooltipUnit = 'Star'
  let legendEnabled = true
  let onClick = null
  let weekStart = 0 //0 for Sunday, 1 for Monday
  let locale = {
    months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    days: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
    No: 'No',
    on: 'on',
    Less: 'Less',
github binary-com / binary-static / src / javascript / _common / base / gtm.js View on Github external
bom_account_type  : ClientBase.getAccountType(),
            bom_currency      : ClientBase.get('currency'),
            bom_country       : get_settings.country,
            bom_country_abbrev: get_settings.country_code,
            bom_email         : get_settings.email,
            url               : window.location.href,
            bom_today         : moment_now.unix(),
        };

        if (is_new_account) {
            data.event = 'new_account';
            data.bom_date_joined = data.bom_today;
        }

        if (!ClientBase.get('is_virtual')) {
            data.bom_age       = moment_now.diff(moment.unix(get_settings.date_of_birth).utc(), 'year');
            data.bom_firstname = get_settings.first_name;
            data.bom_lastname  = get_settings.last_name;
            data.bom_phone     = get_settings.phone;
        }

        if (login_event) {
            data.event = login_event;
            BinarySocket.wait('mt5_login_list').then((response) => {
                (response.mt5_login_list || []).forEach((obj) => {
                    const acc_type = (ClientBase.getMT5AccountType(obj.group) || '')
                        .replace('real_vanuatu', 'financial')
                        .replace('real_svg', 'financial')
                        .replace('vanuatu_', '')
                        .replace('svg_', '')
                        .replace(/svg/, 'gaming'); // i.e. financial_cent, demo_cent, demo_gaming, real_gaming
                    if (acc_type) {
github Ovilia / 2019-typography-calendar / src / app / app.component.ts View on Github external
initializeApp() {
        moment.locale('zh-cn');

        const enterHome = () => {
            this.statusBar.styleDefault();
            this.splashScreen.hide();
        };

        this.platform.ready().then(() => {
            // Okay, so the platform is ready and our plugins are available.
            // Here you can do any higher level native things you might need.
            if (this.platform.is('android')) {
                this.androidFullScreen.isImmersiveModeSupported()
                    .then(err => {
                        console.log(err);
                        return this.androidFullScreen.immersiveMode();
                    })
                    .then(enterHome)
github SwitchbladeBot / switchblade / src / commands / utility / weather.js View on Github external
async run ({ t, author, channel, language }, address) {
    moment.locale(language)
    channel.startTyping()
    const city = await this.client.apis.gmaps.searchCity(address)
    if (city) {
      const [ lang ] = language.split('-')
      const { lat, lng } = city.geometry.location
      // TODO: configurable units
      const { currently, daily: { data: daily }, timezone } = await this.client.apis.darksky.getForecast(lat, lng, { lang, units: 'ca' })

      const now = daily.shift()
      const weatherInfo = {
        now: {
          temperature: `${this.tempHumanize(currently.temperature, true)}`,
          wind: `${this.tempHumanize(currently.windSpeed)} km/h`,
          max: this.tempHumanize(now.temperatureHigh),
          min: this.tempHumanize(now.temperatureLow),
          icon: currently.icon
github opfab / operatorfabric-core / ui / main / src / app / modules / feed / feed.component.ts View on Github external
ngOnInit() {
        this.lightCards$ = this.store.pipe(
            select(feedSelectors.selectFilteredFeed),
            catchError(err => of([]))
        );
        this.selection$ = this.store.select(feedSelectors.selectLightCardSelection);
        this.store.select(buildConfigSelector('feed.timeline.hide'))
            .subscribe(v=>this.hideTimeLine = v);
    
            moment.updateLocale('en', { week: {
                dow: 6, // First day of week is Saturday
                doy: 12 // First week of year must contain 1 January (7 + 6 - 1)
            }});
    
    }