UNPKG

effect-ts-laws

Version:
41 lines 1.83 kB
import { DateTime as DT, Duration as DU, pipe } from 'effect'; import fc from 'fast-check'; import { tinyInteger } from './data.js'; import { Monad as arbitraryMonad } from './instances.js'; const { flatMap, map } = arbitraryMonad; /** * Finite `Duration` arbitrary. * @category arbitraries */ export const duration = fc.oneof(tinyInteger.map(_ => DU.millis(_)), tinyInteger.map(_ => DU.seconds(_)), tinyInteger.map(_ => DU.minutes(_)), tinyInteger.map(_ => DU.hours(_)), tinyInteger.map(_ => DU.days(_)), tinyInteger.map(_ => DU.weeks(_))); /** * Arbitrary for a duration and its bounds. * @category arbitraries */ export const boundedDuration = pipe(fc.tuple(tinyInteger, tinyInteger), flatMap(([first, second]) => { const [min, max] = first < second ? [first, second] : [second, first]; const bounded = fc.constant({ compare: DU.Order, maxBound: DU.millis(min), minBound: DU.millis(max), }); return fc.tuple(fc.constant(map(fc.integer({ min, max }), i => DU.millis(i))), bounded); })); /** * `DateTime.TimeZone.Offset` arbitrary. The offset is clamped between -14hrs * and 14hrs, allowing for a maximum 28hrs offset between any two points on * earth. * @category arbitraries */ export const offsetTimezone = pipe({ min: -14, max: 14 }, fc.integer, map(offset => DT.zoneMakeOffset(offset))); /** * `DateTime.Utc` arbitrary. Only valid dates are generated. * @category arbitraries */ export const utc = (constraints) => pipe({ noInvalidDate: true, ...constraints }, fc.date, map(date => DT.unsafeFromDate(date))); /** * `DateTime.Zoned` arbitrary. Only valid dates are generated. * @category arbitraries */ export const zoned = (constraints) => pipe(fc.tuple(utc(constraints), offsetTimezone), map(([utc, zone]) => DT.setZone(utc, zone))); //# sourceMappingURL=time.js.map