Sha256: d7b96418da826e25340350bf09ae311dbcf14f86be3d001ed198bbc149b5c448

Contents?: true

Size: 1.45 KB

Versions: 52

Compression:

Stored size: 1.45 KB

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,
}

const ABBR_DAYS = ['SU', 'M', 'T', 'W', 'TH', 'F', 'S']

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('%Z')
  }

  toCustomFormat(format = '%-m/%-d') {
    return this.value.strftime(format)
  }

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

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

  toMonthNum() {
    return this.value.strftime('%-m')
  }

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

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

  toDayAbbr() {
    return ABBR_DAYS[this.value.day()]
  }

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

  toHour() {
    return this.value.strftime('%l')
  }

  toMinute() {
    return this.value.strftime('%M')
  }

  toMeridian() {
    return this.value.strftime('%P')[0]
  }

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

  toTime() {
    return this.value.strftime('%I:%M')
  }

  toTimezone() {
    return this.value.strftime('%Z')
  }

  toTimeWithMeridian() {
    return this.toTime() + this.toMeridian()
  }
}

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
playbook_ui-6.0.1.pre.alpha6 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-6.0.1.pre.alpha5 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-6.0.1.pre.alpha4 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-6.0.1.pre.alpha3 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-6.0.1.pre.alpha2 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.2.0.pre.alpha15 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.2.0.pre.alpha14 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.2.0.pre.alpha13 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-6.0.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.2.0.pre.alpha12 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-6.0.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.2.0.pre.alpha11 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.5.1.pre.alpha4 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.5.1.pre.alpha3 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.5.1.pre.alpha2 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.5.1.pre.alpha1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.2.0.pre.alpha10 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.5.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.5.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-5.5.0.pre.alpha1 app/pb_kits/playbook/pb_kit/dateTime.js