Sha256: f90bb16cfac2d784728ffb540cac82f465fe117708f4478c0852b63f557e3640

Contents?: true

Size: 882 Bytes

Versions: 3

Compression:

Stored size: 882 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(zone='America/New_York') {
    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

3 entries across 3 versions & 1 rubygems

Version Path
playbook_ui-3.1.0 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-3.0.1 app/pb_kits/playbook/pb_kit/dateTime.js
playbook_ui-3.0.0 app/pb_kits/playbook/pb_kit/dateTime.js