Sha256: 3266d98ae2b753978683a2881890cfb0129ccfd9843c3e46e95c70c90a9a2854

Contents?: true

Size: 860 Bytes

Versions: 29

Compression:

Stored size: 860 Bytes

Contents

/* @flow */
/*eslint-disable flowtype/space-before-type-colon */

import moment from 'moment'
require('moment-strftime')
require('moment-timezone')

type DateTimeType = {
  value: String | Date,
  zone?: String,
}

export default class DateTime {
  constructor({ value, zone = 'America/New_York' }: DateTimeType) {
    this.value = this.convertToTimestampZone(value, zone)
  }

  convertToTimestampZone(value, zone) {
    return moment(value).tz(zone)
  }

  convertToTimezone() {
    return this.value.strftime('%a')
  }

  toYear() {
    return this.value.strftime('%Y')
  }

  toMonth() {
    return this.value.strftime('%b')
  }

  toMonthFull() {
    return this.value.strftime('%B')
  }

  toDay() {
    return this.value.strftime('%e')
  }

  toWeekday() {
    return this.value.strftime('%a')
  }

  toIso() {
    return this.value.toISOString()
  }
}

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
playbook_ui-4.11.0.pre.alpha3 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.11.0.pre.alpha.pre.2 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.10.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.10.0.pre.alpha1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.9.0.pre.alpha1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.9.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.8.2 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.8.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.7.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.7.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.6.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.6.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.5.2 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.5.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.5.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.4.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.4.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.3.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.3.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-4.2.0 app/pb_kits/playbook/pb_kit/dateTime.js