Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion shared/src/model/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { now as getNow } from 'mobx-utils'

const { range } = extendMoment(moment as any);

//console.log({ range })
// https://moment.github.io/luxon/docs/manual/formatting
type LocaleFormat = 'DATE_SHORT' | 'DATE_MED' | 'DATE_MED_WITH_WEEKDAY' | 'DATE_FULL' | 'DATE_HUGE' | 'TIME_SIMPLE' | 'TIME_WITH_SECONDS' | 'TIME_WITH_SHORT_OFFSET' | 'TIME_WITH_LONG_OFFSET' | 'TIME_24_SIMPLE' | 'TIME_24_WITH_SECONDS' | 'TIME_24_WITH_SHORT_OFFSET' | 'TIME_24_WITH_LONG_OFFSET' | 'DATETIME_SHORT' | 'DATETIME_MED' | 'DATETIME_FULL' | 'DATETIME_HUGE' | 'DATETIME_SHORT_WITH_SECONDS' | 'DATETIME_MED_WITH_SECONDS' | 'DATETIME_FULL_WITH_SECONDS' | 'DATETIME_HUGE_WITH_SECONDS'

let shiftMs = 0;
const defaultResolution = 1000 * 60; // one minute resolution
Expand Down Expand Up @@ -42,6 +43,8 @@ export type { DurationUnit }
export type ComparableValue = Date | Time | LDT
export type TimeInputs = Time | Date | string | number | LDT

export type DATE_TIME_FORMAT = keyof typeof LDT // DateTimeFormatOptions


export default class Time {
static get now() {
Expand Down Expand Up @@ -131,6 +134,8 @@ export default class Time {
get isUnknown() { return this._value === Time.unknown._value }
get isValid() { return Boolean(!this.isUnknown && this._value.isValid) }

toLocaleString(fmt: LocaleFormat) { return this._value.toLocaleString(LDT[fmt]) }

toFormat(fmt: string) { return this._value.toFormat(fmt) }
// left for comatibility with momentjs, do not use for new code
format(fmt: string) { return this.asMoment.format(fmt) }
Expand Down
9 changes: 9 additions & 0 deletions tutor/specs/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ interface TutorTestConfig {
declare global {
const testConfig: TutorTestConfig
interface Window { _MODELS: any; }

namespace jest {
interface Matchers<R> {
toHaveRendered(match: string): R
}
interface Expect {
snapshot<T>(reactEl: any): JestMatchers<T>
}
}
}
Loading