Skip to content

Instantly share code, notes, and snippets.

@ryanleecode
Created June 28, 2025 07:09
Show Gist options
  • Save ryanleecode/93b43f351a7cd43d67732da558caff13 to your computer and use it in GitHub Desktop.
Save ryanleecode/93b43f351a7cd43d67732da558caff13 to your computer and use it in GitHub Desktop.
Effect TS Value Class
import { Match, Schema as S } from 'effect'
import * as Duration from 'effect/Duration'
const _TimeRangeInput = S.Literal('24h', '48h', '7d', '30d', '90d')
export class TimeRangeInput extends S.Class<TimeRangeInput>('TimeRangeInput')({
value: _TimeRangeInput,
}) {
static readonly TimeRangeInput = _TimeRangeInput
toDurationInput(): Duration.DurationInput {
return Match.value(this.value).pipe(
Match.when('24h', () => '24 hours' satisfies Duration.DurationInput as Duration.DurationInput),
Match.when('48h', () => '48 hours' satisfies Duration.DurationInput as Duration.DurationInput),
Match.when('7d', () => '7 days' satisfies Duration.DurationInput as Duration.DurationInput),
Match.when('30d', () => '30 days' satisfies Duration.DurationInput as Duration.DurationInput),
Match.when('90d', () => '90 days' satisfies Duration.DurationInput as Duration.DurationInput),
Match.exhaustive,
)
}
}
export namespace TimeRangeInput {
export type TimeRangeInput = S.Schema.Type<typeof TimeRangeInput.TimeRangeInput>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment