Skip to content

Commit

Permalink
further organization
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Mar 29, 2024
1 parent 38c3983 commit 3758804
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions packages/temporal-polyfill/src/funcApi/roundUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,7 @@ import { Unit } from '../internal/units'
import { bindArgs } from '../internal/utils'
import { moveByIsoWeeks } from './moveUtils'

/*
For year/month/week only
*/
export function roundDateTimeToInterval<C, S extends DateSlots<C>>(
computeInterval: (slots: S) => IsoDateTimeInterval,
slots: S,
roundingMode: RoundingMode,
): S & IsoDateTimeFields {
const [isoFields0, isoFields1] = computeInterval(slots)
const epochNano0 = isoToEpochNano(isoFields0)!
const epochNano1 = isoToEpochNano(isoFields1)!
const epochNano = isoToEpochNano(slots)!
const frac = computeEpochNanoFrac(epochNano, epochNano0, epochNano1)
const grow = roundWithMode(frac, roundingMode)
const isoFieldsRounded = grow ? isoFields1 : isoFields0
return {
...slots,
...isoFieldsRounded,
}
}

// Utils: Floor
// Floor
// -----------------------------------------------------------------------------

export function computeYearFloor(
Expand Down Expand Up @@ -70,7 +49,7 @@ export const computeSecFloor = bindArgs(clearIsoFields, Unit.Second)
export const computeMilliFloor = bindArgs(clearIsoFields, Unit.Millisecond)
export const computeMicroFloor = bindArgs(clearIsoFields, Unit.Microsecond)

// Utils: Ceil
// Ceil
// -----------------------------------------------------------------------------

export function computeYearCeil(slots: DateSlots<string>): IsoDateTimeFields {
Expand All @@ -85,7 +64,7 @@ export function computeIsoWeekCeil(slots: IsoDateFields): IsoDateTimeFields {
return computeIsoWeekInterval(slots)[1]
}

// Utils: Interval
// Interval
// -----------------------------------------------------------------------------

export function computeYearInterval(
Expand Down Expand Up @@ -119,3 +98,24 @@ export function computeIsoWeekInterval(
const isoFields1 = moveByIsoWeeks(isoFields0, 1)
return [isoFields0, isoFields1]
}

/*
For year/month/week only
*/
export function roundDateTimeToInterval<C, S extends DateSlots<C>>(
computeInterval: (slots: S) => IsoDateTimeInterval,
slots: S,
roundingMode: RoundingMode,
): S & IsoDateTimeFields {
const [isoFields0, isoFields1] = computeInterval(slots)
const epochNano0 = isoToEpochNano(isoFields0)!
const epochNano1 = isoToEpochNano(isoFields1)!
const epochNano = isoToEpochNano(slots)!
const frac = computeEpochNanoFrac(epochNano, epochNano0, epochNano1)
const grow = roundWithMode(frac, roundingMode)
const isoFieldsRounded = grow ? isoFields1 : isoFields0
return {
...slots,
...isoFieldsRounded,
}
}

0 comments on commit 3758804

Please sign in to comment.