Sha256: fadba14d32613be7f05ecf9176065eed95ab523dbef1f2389b7566d11bf86cd7

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 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')
  }

  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()
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
playbook_ui-4.11.0 app/pb_kits/playbook/pb_kit/dateTime.js