2020-08-19 00:19:12 +03:00
|
|
|
import { either } from "fp-ts/lib/Either";
|
2021-06-06 23:51:32 +02:00
|
|
|
import * as t from "io-ts";
|
2020-08-19 00:19:12 +03:00
|
|
|
import { isValidTimezone } from "./isValidTimezone";
|
|
|
|
|
|
|
|
export const tValidTimezone = new t.Type<string, string>(
|
|
|
|
"tValidTimezone",
|
|
|
|
(s): s is string => typeof s === "string",
|
|
|
|
(from, to) =>
|
|
|
|
either.chain(t.string.validate(from, to), input => {
|
|
|
|
return isValidTimezone(input) ? t.success(input) : t.failure(from, to, `Invalid timezone: ${input}`);
|
|
|
|
}),
|
|
|
|
s => s,
|
|
|
|
);
|