diff --git a/booking-app/app.development.yaml b/booking-app/app.development.yaml index 7e4ead83..c7e6f3a8 100644 --- a/booking-app/app.development.yaml +++ b/booking-app/app.development.yaml @@ -10,6 +10,7 @@ automatic_scaling: env_variables: NEXT_PUBLIC_BRANCH_NAME: "development" NODE_OPTIONS: "--max-old-space-size=4096" + TZ: "America/New_York" build_env_variables: NODE_OPTIONS: "--max-old-space-size=4096" diff --git a/booking-app/app.production.yaml b/booking-app/app.production.yaml index f40d61e2..2640c099 100644 --- a/booking-app/app.production.yaml +++ b/booking-app/app.production.yaml @@ -10,6 +10,7 @@ automatic_scaling: env_variables: NEXT_PUBLIC_BRANCH_NAME: "production" NODE_OPTIONS: "--max-old-space-size=4096" + TZ: "America/New_York" build_env_variables: NODE_OPTIONS: "--max-old-space-size=4096" diff --git a/booking-app/app.staging.yaml b/booking-app/app.staging.yaml index 6f890331..f53bfbb7 100644 --- a/booking-app/app.staging.yaml +++ b/booking-app/app.staging.yaml @@ -10,6 +10,7 @@ automatic_scaling: env_variables: NEXT_PUBLIC_BRANCH_NAME: "staging" NODE_OPTIONS: "--max-old-space-size=4096" + TZ: "America/New_York" build_env_variables: NODE_OPTIONS: "--max-old-space-size=4096" diff --git a/booking-app/app/api/bookings/route.ts b/booking-app/app/api/bookings/route.ts index 371755f6..468ccb85 100644 --- a/booking-app/app/api/bookings/route.ts +++ b/booking-app/app/api/bookings/route.ts @@ -161,13 +161,11 @@ export async function POST(request: NextRequest) { equipmentCheckedOut: false, ...data, }); - console.log(" Done serverSaveDataToFirestore booking"); await serverSaveDataToFirestore(TableNames.BOOKING_STATUS, { calendarEventId, email, requestedAt: Timestamp.now(), }); - console.log(" Done serverSaveDataToFirestore booking status"); await handleBookingApprovalEmails( isAutoApproval, diff --git a/booking-app/components/src/client/utils/serverDate.ts b/booking-app/components/src/client/utils/serverDate.ts index 050515a8..c4651a57 100644 --- a/booking-app/components/src/client/utils/serverDate.ts +++ b/booking-app/components/src/client/utils/serverDate.ts @@ -1,5 +1,7 @@ import { Timestamp } from "firebase-admin/firestore"; -import { format } from "date-fns"; +import { toZonedTime } from "date-fns-tz"; +import { parseISO } from "date-fns"; +import { format } from "date-fns-tz"; type DateInput = Date | Timestamp | { [key: string]: any } | number | string; @@ -15,15 +17,26 @@ const parseTimestamp = (value: DateInput): Timestamp => { }; export const serverFormatDate = ( - input: DateInput, + input: string, timeZone: string = "America/New_York" ): string => { if (!input) return ""; try { - const timestamp = parseTimestamp(input); - const date = timestamp.toDate(); - const zonedDate = new Date(date.toLocaleString("en-US", { timeZone })); - return format(zonedDate, "yyyy-MM-dd hh:mm a"); + const date = new Date(input); + + const zonedDate = toZonedTime(date, timeZone); + + const formattedResult = format(zonedDate, "yyyy-MM-dd hh:mm a", { + timeZone, + }); + + console.log("Input:", input); + console.log("Parsed Date:", date.toISOString()); + console.log("Zoned Date:", zonedDate.toString()); + console.log("Formatted Result:", formattedResult); + console.log("Timezone:", timeZone); + + return formattedResult; } catch (error) { console.error("Error formatting date:", error, "Input:", input); return ""; diff --git a/booking-app/lib/googleClient.ts b/booking-app/lib/googleClient.ts index 80a3be08..2da94dcd 100644 --- a/booking-app/lib/googleClient.ts +++ b/booking-app/lib/googleClient.ts @@ -14,9 +14,6 @@ const refreshAccessTokenIfNeeded = async (oauth2Client) => { const currentTime = Date.now(); const tokenExpiryTime = oauth2Client.credentials.expiry_date; - console.log("Current time:", new Date(currentTime)); - console.log("Token expiry:", new Date(tokenExpiryTime)); - if (!tokenExpiryTime || currentTime >= tokenExpiryTime - 60000) { // 1分前に更新 try { diff --git a/booking-app/package-lock.json b/booking-app/package-lock.json index c9b33bc4..752525e8 100644 --- a/booking-app/package-lock.json +++ b/booking-app/package-lock.json @@ -24,6 +24,7 @@ "axios": "^1.7.2", "bootstrap": "^5.3.3", "date-fns": "^3.6.0", + "date-fns-tz": "^3.1.3", "dayjs": "^1.11.12", "firebase": "^10.12.4", "firebase-admin": "^12.2.0", @@ -5527,6 +5528,14 @@ "url": "https://github.com/sponsors/kossnocorp" } }, + "node_modules/date-fns-tz": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-3.1.3.tgz", + "integrity": "sha512-ZfbMu+nbzW0mEzC8VZrLiSWvUIaI3aRHeq33mTe7Y38UctKukgqPR4nTDwcwS4d64Gf8GghnVsroBuMY3eiTeA==", + "peerDependencies": { + "date-fns": "^3.0.0" + } + }, "node_modules/dayjs": { "version": "1.11.12", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.12.tgz", diff --git a/booking-app/package.json b/booking-app/package.json index 2dd39195..ba14c6ac 100644 --- a/booking-app/package.json +++ b/booking-app/package.json @@ -27,6 +27,7 @@ "axios": "^1.7.2", "bootstrap": "^5.3.3", "date-fns": "^3.6.0", + "date-fns-tz": "^3.1.3", "dayjs": "^1.11.12", "firebase": "^10.12.4", "firebase-admin": "^12.2.0",