Skip to content

Commit 9bba388

Browse files
committed
feat: add timezone support for date code replacement
1 parent 48e9ce8 commit 9bba388

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ADMIN_SECRET=rDKs0Drx6Rmnqz09s1pDBYOvszpOkuPR
22
FALLBACK_URL=http://isittuesday.co.uk/
3+
TIMEZONE=America/New_York
34

45
SOURCE=google-sheets
56
GOOGLE_SHEET_DOC_ID=06d8f872-6083-44c3-92a0-fbd82565f98f

src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface AirtableConfig {
2323
interface Config extends CleanedEnvAccessors {
2424
adminSecret: string;
2525
fallbackUrl: string;
26+
timezone: string;
2627
redisUrl?: string;
2728
source: LinkSourceType;
2829
googleConfig?: GoogleConfig;
@@ -44,6 +45,7 @@ const env = cleanEnv(process.env, {
4445
ADMIN_SECRET: str({}),
4546
FALLBACK_URL: url({}),
4647
FLY_REDIS_CACHE_URL: str({ default: undefined }),
48+
TIMEZONE: str({}),
4749
SOURCE: linkSource({
4850
choices: Object.values(LinkSourceType),
4951
default: LinkSourceType.GoogleSheets,
@@ -88,6 +90,7 @@ export const config: Config = {
8890
...envConfig,
8991
adminSecret: env.ADMIN_SECRET,
9092
fallbackUrl: env.FALLBACK_URL,
93+
timezone: env.TIMEZONE,
9194
redisUrl: env.FLY_REDIS_CACHE_URL,
9295
source: env.SOURCE,
9396
googleConfig,

src/lib/shortener.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import request from 'superagent';
55

66
import { Cache } from './cache';
77
import { LinkRecord, LinkSource } from './types';
8+
import { config } from '../config';
89

9-
const currentYYMMDD = () => DateTime.now().toFormat('yyMMdd');
10+
const currentYYMMDD = () => DateTime.now().setZone(config.timezone).toFormat('yyMMdd');
1011

1112
export interface LookupPathOptions {
1213
exactMatch: (matchingEntry: string) => void;

0 commit comments

Comments
 (0)