Skip to content

Commit

Permalink
fix: add utc
Browse files Browse the repository at this point in the history
  • Loading branch information
kanitw committed Jun 28, 2023
1 parent 7f6e153 commit fd898bb
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/timeunit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const LOCAL_MULTI_TIMEUNIT_INDEX = {

export type LocalMultiTimeUnit = keyof typeof LOCAL_MULTI_TIMEUNIT_INDEX;

const BINNED_TIMEUNIT_INDEX = {
const LOCAL_BINNED_TIMEUNIT_INDEX = {
binnedyear: 1,
binnedyearquarter: 1,
binnedyearquartermonth: 1,
Expand All @@ -107,7 +107,31 @@ const BINNED_TIMEUNIT_INDEX = {
binnedyeardayofyear: 1
} as const;

export type BinnedTimeUnit = keyof typeof BINNED_TIMEUNIT_INDEX;
export type LocalBinnedTimeUnit = keyof typeof LOCAL_BINNED_TIMEUNIT_INDEX;

const BINNED_UTC_TIMEUNIT_INDEX = {
binnedutcyear: 1,
binnedutcyearquarter: 1,
binnedutcyearquartermonth: 1,

binnedutcyearmonth: 1,
binnedutcyearmonthdate: 1,
binnedutcyearmonthdatehours: 1,
binnedutcyearmonthdatehoursminutes: 1,
binnedutcyearmonthdatehoursminutesseconds: 1,

binnedutcyearweek: 1,
binnedutcyearweekday: 1,
binnedutcyearweekdayhours: 1,
binnedutcyearweekdayhoursminutes: 1,
binnedutcyearweekdayhoursminutesseconds: 1,

binnedutcyeardayofyear: 1
};

export type UtcBinnedTimeUnit = keyof typeof BINNED_UTC_TIMEUNIT_INDEX;

export type BinnedTimeUnit = LocalBinnedTimeUnit | UtcBinnedTimeUnit;

export function isBinnedTimeUnit(
timeUnit: TimeUnit | BinnedTimeUnit | TimeUnitParams | undefined
Expand All @@ -122,10 +146,6 @@ export function isBinnedTimeUnitString(timeUnit: TimeUnit | BinnedTimeUnit | und
return timeUnit && timeUnit.startsWith('binned');
}

export function getLocalTimeUnitFromBinnedTimeUnit(timeUnit: BinnedTimeUnit): LocalTimeUnit {
return timeUnit.substring(6) as LocalTimeUnit;
}

export const UTC_MULTI_TIMEUNIT_INDEX = {
utcyearquarter: 1,
utcyearquartermonth: 1,
Expand Down Expand Up @@ -348,7 +368,7 @@ export function normalizeTimeUnit(timeUnit: TimeUnit | BinnedTimeUnit | TimeUnit
if (isString(timeUnit)) {
if (isBinnedTimeUnitString(timeUnit)) {
params = {
unit: getLocalTimeUnitFromBinnedTimeUnit(timeUnit),
unit: timeUnit.substring(6) as TimeUnit,
binned: true
};
} else {
Expand Down

0 comments on commit fd898bb

Please sign in to comment.