Skip to content

Commit e11b8c9

Browse files
committed
chore: add timezone type
1 parent 2128c69 commit e11b8c9

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

app/Scheduler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { schedule } from '@stacksjs/scheduler'
99
* questions, feel free to reach out via Discord or GitHub Discussions.
1010
*/
1111
export default function () {
12-
schedule.job('name').everyMinute()
12+
schedule.job('name').everyMinute().setTimeZone('America/Los_Angeles')
1313
schedule.action('name').everyFiveMinutes()
1414
schedule.command('echo "Hello, world!"').daily()
1515
}

storage/framework/core/scheduler/src/schedule.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CatchCallbackFn, CronOptions } from './'
2+
import type { Timezone } from './types'
23
import { log, runCommand } from '@stacksjs/cli'
34
import { Cron } from './'
45

@@ -11,7 +12,7 @@ interface BaseSchedule {
1112
withContext: (context: any) => this
1213
withInterval: (seconds: number) => this
1314
between: (startAt: string | Date, stopAt: string | Date) => this
14-
setTimeZone: (timezone: string) => this
15+
setTimeZone: (timezone: Timezone) => this
1516
}
1617

1718
// Interface for schedule before timing is set
@@ -41,9 +42,8 @@ interface TimedSchedule extends BaseSchedule {
4142

4243
export class Schedule implements UntimedSchedule {
4344
private static jobs = new Map<string, Cron>()
44-
4545
private cronPattern = ''
46-
private timezone = 'America/Los_Angeles'
46+
private timezone: Timezone = 'America/Los_Angeles'
4747
private readonly task: () => void
4848
private options: {
4949
timezone?: string
@@ -147,7 +147,7 @@ export class Schedule implements UntimedSchedule {
147147
return this as TimedSchedule
148148
}
149149

150-
setTimeZone(timezone: string): this {
150+
setTimeZone(timezone: Timezone): this {
151151
this.timezone = timezone
152152
this.options.timezone = timezone
153153
return this
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
11
export type IntRange<Min extends number, Max extends number> = number extends Min | Max
22
? never
33
: number | [Min | number, Max | number]
4+
5+
// IANA Timezone
6+
export type Timezone =
7+
| 'Africa/Abidjan'
8+
| 'Africa/Accra'
9+
| 'Africa/Addis_Ababa'
10+
| 'Africa/Algiers'
11+
| 'Africa/Cairo'
12+
| 'Africa/Casablanca'
13+
| 'Africa/Lagos'
14+
| 'Africa/Nairobi'
15+
| 'America/Anchorage'
16+
| 'America/Argentina/Buenos_Aires'
17+
| 'America/Bogota'
18+
| 'America/Caracas'
19+
| 'America/Chicago'
20+
| 'America/Denver'
21+
| 'America/Detroit'
22+
| 'America/Halifax'
23+
| 'America/Los_Angeles'
24+
| 'America/Mexico_City'
25+
| 'America/New_York'
26+
| 'America/Phoenix'
27+
| 'America/Santiago'
28+
| 'America/Sao_Paulo'
29+
| 'America/Toronto'
30+
| 'America/Vancouver'
31+
| 'Asia/Bangkok'
32+
| 'Asia/Dubai'
33+
| 'Asia/Hong_Kong'
34+
| 'Asia/Istanbul'
35+
| 'Asia/Jakarta'
36+
| 'Asia/Jerusalem'
37+
| 'Asia/Karachi'
38+
| 'Asia/Kolkata'
39+
| 'Asia/Kuwait'
40+
| 'Asia/Manila'
41+
| 'Asia/Shanghai'
42+
| 'Asia/Singapore'
43+
| 'Asia/Tokyo'
44+
| 'Australia/Melbourne'
45+
| 'Australia/Perth'
46+
| 'Australia/Sydney'
47+
| 'Europe/Amsterdam'
48+
| 'Europe/Athens'
49+
| 'Europe/Belgrade'
50+
| 'Europe/Berlin'
51+
| 'Europe/Brussels'
52+
| 'Europe/Budapest'
53+
| 'Europe/Copenhagen'
54+
| 'Europe/Dublin'
55+
| 'Europe/Helsinki'
56+
| 'Europe/Istanbul'
57+
| 'Europe/Lisbon'
58+
| 'Europe/London'
59+
| 'Europe/Madrid'
60+
| 'Europe/Moscow'
61+
| 'Europe/Paris'
62+
| 'Europe/Prague'
63+
| 'Europe/Rome'
64+
| 'Europe/Stockholm'
65+
| 'Europe/Vienna'
66+
| 'Europe/Warsaw'
67+
| 'Europe/Zurich'
68+
| 'Pacific/Auckland'
69+
| 'Pacific/Fiji'
70+
| 'Pacific/Honolulu'
71+
| 'UTC'

storage/framework/ide/dictionary.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
Ababa
12
Abellanosa
3+
Addis
24
adelino
35
alefragnani
46
alrighty

0 commit comments

Comments
 (0)