Skip to content

Commit

Permalink
fix: timezones and build
Browse files Browse the repository at this point in the history
  • Loading branch information
badosz0 committed Apr 8, 2024
1 parent 469b873 commit 04c8211
Show file tree
Hide file tree
Showing 4 changed files with 619 additions and 314 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "holy-time",
"version": "4.1.0",
"version": "4.2.0",
"description": "Utility functions",
"repository": "Yet another (type-safe) date time library",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"test:watch": "TZ=UTC vitest watch -c ./src/vitest.config.ts",
"test": "TZ=UTC vitest run -c ./src/vitest.config.ts"
"test": "TZ=UTC vitest run -c ./src/vitest.config.ts",
"build": "tsup src --dts --minify --format cjs,esm --out-dir dist"
},
"author": "Bartosz Krol <[email protected]>",
"license": "MIT",
Expand All @@ -25,5 +27,8 @@
"type-fest": "^3.0.0",
"typescript": "^4.8.3",
"vitest": "^0.34.6"
},
"dependencies": {
"tsup": "^8.0.2"
}
}
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,12 @@ export const TIMEZONES = [
'Pacific/Truk',
'Pacific/Wake',
'Pacific/Wallis',
'UTC',
] as const;

// TODO: add more timezones
export const TIMEZONE_MAP = {
'UTC+0': 'Europe/London',
'UTC+0': 'UTC',
} as const;

export type TimeZone = typeof TIMEZONES[number] | keyof typeof TIMEZONE_MAP;
10 changes: 5 additions & 5 deletions src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class HolyTime {
}

public static between(timeA: TimeResolvable, timeB: TimeResolvable): HolyDuration {
return this.duration(Math.abs(HolyTime.resolveDate(timeA).getTime() - HolyTime.resolveDate(timeB).getTime()))
return this.duration(Math.abs(HolyTime.resolveDate(timeA).getTime() - HolyTime.resolveDate(timeB).getTime()));
}

public static isAfter(timeA: TimeResolvable, timeB: TimeResolvable): boolean {
Expand Down Expand Up @@ -273,7 +273,7 @@ export class HolyTime {
public get<T extends 'object' | GetUnit>(unit: T, timeZone?: TimeZone): T extends 'object' ? Record<GetUnit, number> : number {
const date = HolyTime.adjustToTimeZone(this.date, timeZone);

const object: Record<GetUnit, number> = {
const object: Record<GetUnit, number> = {
millisecond: date.getMilliseconds(),
second: date.getSeconds(),
minute: date.getMinutes(),
Expand All @@ -282,11 +282,11 @@ export class HolyTime {
week: Math.ceil(HolyTime.between(this.startOf('year', timeZone), date).in('weeks')),
month: date.getMonth() + 1,
year: date.getFullYear(),
}
};

return unit === 'object'
? object
: object[unit as GetUnit] as any
? object
: object[unit as GetUnit] as any;
}

public getDate(): Date {
Expand Down
Loading

0 comments on commit 04c8211

Please sign in to comment.