summaryrefslogtreecommitdiff
path: root/src/duration.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-12-15 01:57:28 -0800
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-12-15 02:05:18 -0800
commit4f1e974623f7e38693d3e202cd387c51f652b9d8 (patch)
tree947892a7f7608cb31424c8c37adea7c26a857bee /src/duration.ts
parent53187bede7e871ceca8fe4fabd18822002eb9316 (diff)
downloaduptime-4f1e974623f7e38693d3e202cd387c51f652b9d8.tar.gz
uptime-4f1e974623f7e38693d3e202cd387c51f652b9d8.zip
logout on end
Diffstat (limited to 'src/duration.ts')
-rw-r--r--src/duration.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/duration.ts b/src/duration.ts
index 3d1a44c..e8dc7d1 100644
--- a/src/duration.ts
+++ b/src/duration.ts
@@ -12,6 +12,7 @@ export enum DurationUnit {
MINUTE,
HOUR,
}
+
const durationUnitMap: Record<string, DurationUnit> = {
ms: DurationUnit.MILLISECOND,
milliseconds: DurationUnit.MILLISECOND,
@@ -153,3 +154,26 @@ export const parse = (duration: string): E.Either<string, Duration> => {
E.map(build),
);
};
+
+export const transformDurations = (obj: any): E.Either<string, any> => {
+ const transform = (o: any): E.Either<string, any> => {
+ const entries = Object.entries(o);
+
+ for (let [key, value] of entries) {
+ if (key === "duration" && typeof value === "string") {
+ return parse(value);
+ } else if (typeof value === "object" && value !== null) {
+ const result = transform(value);
+ if (E.isLeft(result)) {
+ return result;
+ } else {
+ o[key] = result.right;
+ }
+ }
+ }
+
+ return E.right(o);
+ };
+
+ return transform(obj);
+}