Skip to content

Commit

Permalink
Fix date for timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
JHWelch committed Jan 11, 2024
1 parent d84dd6d commit 2c4c552
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
23 changes: 17 additions & 6 deletions server/src/controllers/cronController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type Request, type Response } from 'express'
import FirestoreAdapter from '../data/firestore/firestoreAdapter'
import { dateToString } from '../data/dateUtils.js'
import Config from '../config/config'

class CronController {
Expand All @@ -14,7 +13,7 @@ class CronController {
) {}

reminders = async (_req: Request, res: Response): Promise<void> => {
const tomorrow = dateToString(this.tomorrow())
const tomorrow = this.tomorrow()

const week = await this.firestore.getWeek(tomorrow)

Expand Down Expand Up @@ -48,10 +47,22 @@ class CronController {
res.status(200).send('ok')
}

protected tomorrow = (): Date => {
const date = new Date()
date.setDate(date.getDate() + 1)
return date
protected tomorrow = (): string => {
const tomorrow = new Date()
tomorrow.setDate(tomorrow.getDate() + 1)

const tomorrowArray = tomorrow.toLocaleString('en-US', {
timeZone: 'America/Chicago',
year: 'numeric',
month: '2-digit',
day: '2-digit' ,
}).split('/')

return [
tomorrowArray[2],
tomorrowArray[0],
tomorrowArray[1],
].join('-')
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DocumentData, QueryDocumentSnapshot } from 'firebase/firestore'
import SubscriptionController from '../controllers/subscriptionController'
import SubscriptionController from '../controllers/subscriptionController.js'

export default class User {
constructor (
Expand Down
2 changes: 1 addition & 1 deletion server/src/routers/appRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function routes (
): Route[] {
const cacheController = new CacheController(firestore, notion, tmdb)
const calendarController = new CalendarController(config)
const cronController = new CronController(firestore)
const cronController = new CronController(config, firestore)
const rsvpController = new RsvpController(firestore)
const subscriptionController = new SubscriptionController(firestore)
const suggestionController = new SuggestionController(notion)
Expand Down

0 comments on commit 2c4c552

Please sign in to comment.