How to use the d3-time-format.timeFormatLocale function in d3-time-format

To help you get started, we’ve selected a few d3-time-format 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 qlik-oss / picasso.js / packages / picasso.js / src / core / formatter / d3 / timeFormat.js View on Github external
export default function formatter(pattern) { // eslint-disable-line import/prefer-default-export
  let locale = timeFormatLocale({
    dateTime: '%x, %X',
    date: '%-m/%-d/%Y',
    time: '%-I:%M:%S %p',
    periods: ['AM', 'PM'],
    days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  });

  let d3format = locale.format(pattern);

  /**
   * Format a value according to the specified pattern created at construct
   *
   * @param  {Date} value   The number to be formatted
github DefinitelyTyped / DefinitelyTyped / d3-time-format / d3-time-format-tests.ts View on Github external
let shortDays: [string, string, string, string, string, string, string] = localeDef.shortDays;
let months: [string, string, string, string, string, string, string, string, string, string, string, string] = localeDef.months;
let shortMonths: [string, string, string, string, string, string, string, string, string, string, string, string] = localeDef.shortMonths;

localeDef = {
    dateTime: '%a %b %e %X %Y',
    date: '%m/%d/%Y',
    time: '%H:%M:%S',
    periods: ['Vormittag', 'Nachmittag'],
    days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Sonnabend'],
    shortDays: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
    months: ['Januar', 'Februar', 'Maerz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
    shortMonths: ['Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
};

localeObj = d3TimeFormat.timeFormatLocale(localeDef);

localeObj = d3TimeFormat.timeFormatDefaultLocale(localeDef);

let formatFactory: (specifier: string) => ((date: Date) => string) = localeObj.format;
let parseFactory: (specifier: string) => ((dateString: string) => Date) = localeObj.parse;

formatFactory = localeObj.utcFormat;
parseFactory = localeObj.utcParse;
github DefinitelyTyped / DefinitelyTyped / types / d3-time-format / d3-time-format-tests.ts View on Github external
let shortDays: [string, string, string, string, string, string, string] = localeDef.shortDays;
let months: [string, string, string, string, string, string, string, string, string, string, string, string] = localeDef.months;
let shortMonths: [string, string, string, string, string, string, string, string, string, string, string, string] = localeDef.shortMonths;

localeDef = {
    dateTime: '%a %b %e %X %Y',
    date: '%m/%d/%Y',
    time: '%H:%M:%S',
    periods: ['Vormittag', 'Nachmittag'],
    days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Sonnabend'],
    shortDays: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
    months: ['Januar', 'Februar', 'Maerz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
    shortMonths: ['Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
};

localeObj = d3TimeFormat.timeFormatLocale(localeDef);

localeObj = d3TimeFormat.timeFormatDefaultLocale(localeDef);

let formatFactory: (specifier: string) => ((date: Date) => string) = localeObj.format;
let parseFactory: (specifier: string) => ((dateString: string) => Date) = localeObj.parse;

formatFactory = localeObj.utcFormat;
parseFactory = localeObj.utcParse;
github qlik-oss / picasso.js / packages / picasso.js / src / core / formatter / d3 / timeFormat.js View on Github external
format.locale = function localeFn(...args) {
    locale = timeFormatLocale(...args);
    d3format = locale.format(pattern);

    return this;
  };
github orbiting / publikator-frontend / components / Templates / Newsletter / Teaser.js View on Github external
import React from 'react'
import {css} from 'glamor'
import { timeFormatLocale } from 'd3-time-format'
import timeDefinition from 'd3-time-format/locale/de-CH'
import { imageResizeUrl } from 'mdast-react-render/lib/utils'

import { H3 } from './Headlines'
import P from './Paragraph'

const timeFormat = timeFormatLocale(timeDefinition).format

const containerStyle = css({
  height: '100%',
  backgroundColor: '#f2f2f2',
  maxWidth: 290
})
const imageStyle = css({
  display: 'block',
  '& img': {
    width: '100%'
  }
})
const textStyle = css({
  display: 'block',
  padding: '5px 10px 10px',
  textDecoration: 'none',
github orbiting / mdast / packages / template-newsletter / src / web / Teaser.js View on Github external
import React from 'react'
import {css} from 'glamor'
import { timeFormatLocale } from 'd3-time-format'
import timeDefinition from 'd3-time-format/locale/de-CH'
import { imageResizeUrl } from 'mdast-react-render/lib/utils'

import { H3 } from './Headlines'
import P from './Paragraph'

const timeFormat = timeFormatLocale(timeDefinition).format

const containerStyle = css({
  height: '100%',
  backgroundColor: '#f2f2f2'
})
const imageStyle = css({
  display: 'block',
  '& img': {
    width: '100%'
  }
})
const textStyle = css({
  display: 'block',
  padding: '5px 10px 10px',
  textDecoration: 'none',
  '& p': {
github orbiting / crowdfunding-frontend / lib / utils / formats.js View on Github external
if (String(Math.round(value)).length > 4) {
    return chf5Format(value)
  }
  return chf4Format(value)
}

const count4Format = swissNumbers.format(',.0f')
const count5Format = swissNumbers.format(',.0f')
export const countFormat = value => {
  if (String(Math.round(value)).length > 4) {
    return count4Format(value)
  }
  return count5Format(value)
}

export const swissTime = timeFormatLocale({
  'dateTime': '%A, der %e. %B %Y, %X',
  'date': '%d.%m.%Y',
  'time': '%H:%M:%S',
  'periods': ['AM', 'PM'],
  'days': ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
  'shortDays': ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
  'months': ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
  'shortMonths': ['Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
})

export const timeFormat = swissTime.format

const dateFormat = '%d.%m.%Y'
export const parseDate = swissTime.parse(dateFormat)
github orbiting / republik-frontend / lib / utils / format.js View on Github external
if (String(Math.round(value)).length > 4) {
    return chf5Format(value)
  }
  return chf4Format(value)
}

const count4Format = swissNumbers.format('.0f')
const count5Format = swissNumbers.format(',.0f')
export const countFormat = value => {
  if (String(Math.round(value)).length > 4) {
    return count5Format(value)
  }
  return count4Format(value)
}

export const swissTime = timeFormatLocale(timeDefinition)
export const timeFormat = swissTime.format

const dateFormat = '%d.%m.%Y'
export const parseDate = swissTime.parse(dateFormat)

export const formatExcerpt = string =>
  '... ' + string.replace(/\.+$/, '') + '...'
github orbiting / styleguide / src / lib / timeFormat.js View on Github external
import { timeFormatLocale } from 'd3-time-format'
import timeDefinition from 'd3-time-format/locale/de-CH'

const locale = timeFormatLocale(timeDefinition)

export const timeFormat = locale.format
export const timeParse = locale.parse
github apache-superset / superset-ui / packages / superset-ui-time-format / src / factories / createD3TimeFormatter.ts View on Github external
const {
    description,
    formatString = isRequired('formatString'),
    label,
    locale,
    useLocalTime = false,
  } = config;

  const id = useLocalTime ? `${LOCAL_PREFIX}${formatString}` : formatString;
  let formatFunc;

  if (typeof locale === 'undefined') {
    const format = useLocalTime ? timeFormat : utcFormat;
    formatFunc = format(formatString);
  } else {
    const localeObject = timeFormatLocale(locale);
    formatFunc = useLocalTime
      ? localeObject.format(formatString)
      : localeObject.utcFormat(formatString);
  }

  return new TimeFormatter({
    description,
    formatFunc,
    id,
    label,
    useLocalTime,
  });
}