22import admin from 'firebase-admin' ;
33import sendMail from './utils' ;
44import { configureAccount } from '../src/utils/firebase-utils' ;
5+ import { DateTime } from 'luxon' ;
56
67require ( 'dotenv' ) . config ( ) ;
78
@@ -16,19 +17,25 @@ admin.initializeApp({
1617const db = admin . firestore ( ) ;
1718
1819const main = async ( ) => {
19- // current date: 12:00:00 EST the day before the deadline (17:00:00 UTC)
20- const currentDate = new Date ( ) ;
21- // compute 23:59:59.999 EST the day after, i.e. 4:59:59.999 UTC two days after (end of day of the deadline)
22- const deadline = new Date ( currentDate ) ;
23- deadline . setDate ( currentDate . getDate ( ) + 2 ) ;
24- deadline . setHours ( 4 , 59 , 59 , 999 ) ;
20+ // current date: 12:00:00 the day before the deadline (in New York)
21+ const TZ = 'America/New_York' ;
22+
23+ const nowNY = DateTime . now ( ) . setZone ( TZ ) ;
24+
25+ // “due tomorrow” means deadline date is tomorrow in NY time (23:59:59.999 in New York)
26+ const tomorrowStartNY = nowNY . plus ( { days : 1 } ) . startOf ( 'day' ) ;
27+ const tomorrowEndNY = nowNY . plus ( { days : 1 } ) . endOf ( 'day' ) ;
28+
29+ // Convert to UTC millis for querying Firestore (since `deadline` is stored as ms)
30+ const windowStartMs = tomorrowStartNY . toUTC ( ) . toMillis ( ) ;
31+ const windowEndMs = tomorrowEndNY . toUTC ( ) . toMillis ( ) ;
2532
2633 // query Firestore for dev portfolios due on that day
27- console . log ( 'querying for dev portfolios due tomorrow...' ) ;
34+ console . log ( 'querying for dev portfolios due tomorrow... (NY time) ' ) ;
2835 const devPortfolioSnapshot = await db
2936 . collection ( 'dev-portfolio' )
30- . where ( 'deadline' , '>=' , currentDate . getTime ( ) )
31- . where ( 'deadline' , '<=' , deadline . getTime ( ) )
37+ . where ( 'deadline' , '>=' , windowStartMs )
38+ . where ( 'deadline' , '<=' , windowEndMs )
3239 . get ( ) ;
3340
3441 if ( devPortfolioSnapshot . empty ) {
@@ -68,7 +75,8 @@ const main = async () => {
6875 ) . filter ( ( email ) : email is string => email !== null ) ;
6976
7077 const EMAIL_SUBJECT = '[ACTION REQUIRED] Dev Portfolio Submission' ;
71- const deadlineString = devPortfolioData . deadline . toLocaleString ( 'en-US' , {
78+ const deadlineDate = new Date ( devPortfolioData . deadline ) ;
79+ const deadlineString = deadlineDate . toLocaleString ( 'en-US' , {
7280 timeZone : 'America/New_York'
7381 } ) ;
7482 const EMAIL_BODY = `If you are not taking DTI for credit this semester, please ignore.\n\nThis is a reminder to submit your portfolio for ${ devPortfolioName } which is due by ${ deadlineString } . You must contact leads if you require an extension.` ;
0 commit comments