Sha256: 547d25f38bd05c65ae3425df3e1fffc33c9d6c32ebae6628d51163b8fc3caedb

Contents?: true

Size: 1.61 KB

Versions: 246

Compression:

Stored size: 1.61 KB

Contents

import moment, { Moment } from 'moment'
import 'moment-strftime'
import 'moment-timezone'

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

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

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

  convertToTimestampZone(value: string | Date, zone: string) {
    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() {
    const time = this.value.strftime('%I:%M')

    // strftime adds a leading 0 on single hour times. ie 08:31.
    // this removes that 0 to match the rails kit.
    return time.charAt() === '0' ? time.slice(1) : time
  }

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

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

Version data entries

246 entries across 246 versions & 1 rubygems

Version Path
playbook_ui-12.26.0.pre.alpha.multiselectfixes797 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.26.0.pre.alpha.multiselectfixes796 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.26.0.pre.alpha.multiselectfixes795 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.26.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown794 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.play824786 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.26.0 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.railsmultilevelimprovements785 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.railsmultilevelimprovements780 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.PLAY818multilevelrebuild779 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.railsmultilevelimprovements776 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.PLAY818multilevelrebuild774 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.PLAY818multilevelrebuild773 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.PLAY818multilevelrebuild770 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.play822bolddefaultfortitle3764 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.PLAY733DetailKit761 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0.pre.alpha.railsmultilevelimprovements758 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.25.0 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.24.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown756 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.24.0.pre.alpha.play824753 app/pb_kits/playbook/pb_kit/dateTime.ts
playbook_ui-12.24.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown752 app/pb_kits/playbook/pb_kit/dateTime.ts