Skip to content

Commit

Permalink
Merge pull request #419 from ITPNYU/hotfix/time_zone
Browse files Browse the repository at this point in the history
Fixed timezone to America/New_York
  • Loading branch information
rlho authored Sep 25, 2024
2 parents dc2289b + 64c9e5c commit 4ff6f1f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 0 additions & 2 deletions booking-app/app/api/bookings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions booking-app/components/src/client/utils/serverDate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Timestamp } from "firebase-admin/firestore";
import { format } from "date-fns";
import { toZonedTime } from "date-fns-tz";

type DateInput = Date | Timestamp | { [key: string]: any } | number | string;

Expand All @@ -21,9 +22,11 @@ export const serverFormatDate = (
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 utcDate = timestamp.toDate();
const zonedDate = toZonedTime(utcDate, timeZone);
const formattedResult = format(zonedDate, "yyyy-MM-dd hh:mm a");

return formattedResult;
} catch (error) {
console.error("Error formatting date:", error, "Input:", input);
return "";
Expand Down
3 changes: 0 additions & 3 deletions booking-app/lib/googleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions booking-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions booking-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4ff6f1f

Please sign in to comment.