How to use the moment-timezone.locale function in moment-timezone

To help you get started, we’ve selected a few moment-timezone 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 Foundry376 / Mailspring / app / src / date-utils.ts View on Github external
import moment from 'moment-timezone';

// Init locale for moment
moment.locale(navigator.language);

// Initialise moment timezone
const tz = moment.tz.guess();
if (!tz) {
  console.error('DateUtils: TimeZone could not be determined. This should not happen!');
}

const yearRegex = / ?YY(YY)?/;

const Hours = {
  Morning: 9,
  Evening: 20,
  Midnight: 24,
};

const Days = {
github synzen / Discord.RSS / src / util / checkConfig.js View on Github external
traverse(exports.defaultConfigs, userConfig)

  // Miscellaneous checks (such as configs using objects)
  const decodeSettings = userConfig.feeds.decode
  if (typeof decodeSettings === 'object' && decodeSettings !== null) {
    for (const url in decodeSettings) {
      if (typeof decodeSettings[url] !== 'string') invalidConfigs['feeds.decode.' + url] = `Expected string, found ${typeof decodeSettings[url]}`
      else if (!iconv.encodingExists(decodeSettings[url])) fatalInvalidConfigs['feeds.decode.' + url] = `Specified encoding "${decodeSettings[url]}" does not exist for iconv-lite`
    }
  }

  const defLang = userConfig.feeds.dateLanguage
  const langList = userConfig.feeds.dateLanguageList
  if (!langList.includes(defLang)) langList.unshift(defLang)
  for (let u = langList.length - 1; u >= 0; --u) moment.locale(langList[u]) // Set the global moment locale/language to the 0 index item

  let errMsg = ''
  for (const e in fatalInvalidConfigs) errMsg += `\n${e}: ${fatalInvalidConfigs[e]}`
  if (errMsg) {
    return {
      fatal: true,
      message: `Fatal invalid configuration(s) found, must be fixed:\n${errMsg}\n`
    }
  }

  errMsg = ''
  for (const cName in invalidConfigs) errMsg += `\n${cName}: ${invalidConfigs[cName]}`
  if (errMsg) {
    return {
      fatal: false,
      message: `Invalid configuration(s) found, forced defaults have been set:\n${errMsg}\n`
github eventespresso / event-espresso-core / assets / src / vo / date-time / assertions.js View on Github external
export function validateLocale( locale ) {
	if ( ! isString( locale ) ) {
		return false;
	}
	const originalLocale = moment.locale();
	const validationLocale = moment.locale( locale );
	// reset back to original locale
	moment.locale( originalLocale );
	return ! ( locale !== 'en' && validationLocale === 'en' );
}
github eventespresso / event-espresso-core / assets / src / vo / date-time / assertions.js View on Github external
export function validateLocale( locale ) {
	if ( ! isString( locale ) ) {
		return false;
	}
	const originalLocale = moment.locale();
	const validationLocale = moment.locale( locale );
	// reset back to original locale
	moment.locale( originalLocale );
	return ! ( locale !== 'en' && validationLocale === 'en' );
}
github 14islands / vecka.14islands.com / public / models / week.js View on Github external
constructor (weekIndex) {
    moment.updateLocale('sv', {
      ordinal: (number) => {
        const b = number % 10
        const output = (~~(number % 100 / 10) === 1) ? 'e'
          : (b === 1) ? 'a'
          : (b === 2) ? 'a'
          : (b === 3) ? 'e' : 'e'
        return number + ':' + output
      }
    })
    moment.locale('sv')
    this.index = weekIndex || 0
    this.current = moment.tz(TIME_ZONE).add(this.index, 'weeks')
    this.startDayOfWeek = this.current.clone().startOf('isoweek')
    this.endDayOfWeek = this.current.clone().endOf('isoweek')
  }
github arojunior / awesome-feed / src / index.js View on Github external
import apolloClient from './services/apolloClient';
import App from './containers/HomeContainer';
import './assets/App.css';

render(
  
    
      
        
      
    
  ,
  document.getElementById(`root`),
);

moment.locale(window.navigator.userLanguage || window.navigator.language);
moment.tz.setDefault(moment.tz.guess());
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / lib / with-moment-timezone.tsx View on Github external
render() {
      const { i18n, currentUser } = this.props;
      const { timezone } = attributesFor(currentUser);

      moment.locale(i18n.language);

      const timeProps = {
        moment,
        timezone: timezone || moment.tz.guess(),
      };

      return ;
    }
  }
github webkom / lego-webapp / server / server.js View on Github external
import path from 'path';
import fs from 'fs';
import express from 'express';
import morgan from 'morgan';
import moment from 'moment-timezone';
import bunyan from 'bunyan';
import bunyanPretty from 'bunyan-pretty';
import Raven from 'raven';
import cookieParser from 'cookie-parser';
import render from './render';
import config from './env';
import healthCheck from './health';

moment.locale('nb-NO');
const app = express();

app.use(Raven.requestHandler());
app.use(cookieParser());

const log = bunyan.createLogger({
  name: 'lego-webapp',
  release: config.release,
  stream: process.stdout.isTTY ? bunyanPretty() : process.stdout,
  environment: config.environment
});

app.set('host', config.host || '0.0.0.0');
app.set('port', config.port || 3000);
app.set('log', log);