Skip to content

Commit

Permalink
feat: add timeZone
Browse files Browse the repository at this point in the history
Adds the recently announced date-fns utc lib and also migrates date-fns to v4

BREAKING CHANGE!: this pr transitions from  date-fns-tz to date-fns/utc
  • Loading branch information
rubiin committed Sep 28, 2024
1 parent 0dae4fc commit f50be77
Show file tree
Hide file tree
Showing 6 changed files with 550 additions and 385 deletions.
32 changes: 32 additions & 0 deletions docs/timezone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# General Workflow for Handling Timezones

## 1. User Input
- **Frontend Form**: Provide an interface for users to input date and time, using an input field.
- **Timezone Information**: Allow users to select their timezone or use a default based on their system settings.

## 2. Data Submission
- **Capture Input**: When the user submits the form, gather the local date, time, and timezone.
- **Send to Server**: Transmit this data to the server via an API request.

## 3. Server Processing
- **Receive Data**: On the server, receive the incoming request with event details.
- **Convert to UTC**: Use the provided timezone to convert the local date-time to UTC for consistent storage.

## 4. Data Storage
- **Store in Database**: Save the converted UTC date-time in the database to ensure uniformity.

## 5. Data Retrieval
- **Fetch Data**: When retrieving dates from the database, they will be in UTC format.
- **Convert Back to Local Time**: Use the user's timezone to convert the UTC time back to local time for presentation.

## 6. Display to User
- **Format for Display**: Present the local date-time in a user-friendly format.
- **Handle Daylight Saving Time**: Ensure that any daylight saving adjustments are correctly applied.

## 7. Consider Edge Cases
- **Invalid Timezones**: Validate timezone input to ensure it’s recognized.
- **Date Manipulations**: Be cautious with date adjustments to maintain accuracy across time zones.
- **User Settings**: Allow users to set their preferred timezone in their profile settings for a better experience.

## Summary
This workflow ensures accurate handling of date and time across different time zones, minimizing confusion and errors. By converting and storing dates in UTC while providing local conversions based on user input, you create a robust system for managing time-sensitive data.
2 changes: 2 additions & 0 deletions env/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
### Environment File ##################################################################
# This file is a "template" of which env vars need to be defined for your application
########################################################################################
## for timezone, check this link: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

APP_PORT=
APP_PREFIX=
Expand All @@ -12,6 +13,7 @@ CLIENT_URL=
SWAGGER_USER=
ALLOWED_HOSTS=
SWAGGER_PASSWORD=
TZ=

# database
DB_HOST=
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"typescript"
],
"engines": {
"node": ">=20.17.0"
"node": ">=20.0.0"
},
"scripts": {
"build": "nest build",
Expand All @@ -56,10 +56,11 @@
"test:e2e": "jest --config ./test/jest-e2e.json --runInBand --forceExit"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.657.0",
"@aws-sdk/client-ses": "^3.654.0",
"@aws-sdk/client-s3": "^3.658.1",
"@aws-sdk/client-ses": "^3.658.1",
"@casl/ability": "^6.7.1",
"@golevelup/nestjs-rabbitmq": "^5.4.1",
"@date-fns/utc": "^2.1.0",
"@golevelup/nestjs-rabbitmq": "^5.5.0",
"@golevelup/nestjs-stripe": "^0.8.2",
"@golevelup/nestjs-webhooks": "^0.2.18",
"@ladjs/consolidate": "^1.0.4",
Expand Down Expand Up @@ -90,7 +91,7 @@
"@ntegral/nestjs-sentry": "^4.0.1",
"@paralleldrive/cuid2": "^2.2.2",
"@sentry/hub": "^7.114.0",
"@sentry/node": "^8.31.0",
"@sentry/node": "^8.32.0",
"@socket.io/redis-adapter": "^8.3.0",
"@supercharge/request-ip": "^1.2.0",
"argon2": "^0.41.1",
Expand All @@ -100,13 +101,12 @@
"class-validator": "^0.14.1",
"compression": "^1.7.4",
"date-fns": "^4.1.0",
"date-fns-tz": "^3.1.3",
"eta": "^3.5.0",
"firebase-admin": "^12.5.0",
"helmet": "^7.1.0",
"helper-fns": "^2.9.0",
"helper-fns": "^2.9.2",
"ioredis": "^5.4.1",
"isomorphic-dompurify": "^2.15.0",
"isomorphic-dompurify": "^2.16.0",
"joi": "^17.13.3",
"mime": "^4.0.4",
"nestjs-cloudinary": "^2.1.1",
Expand All @@ -124,30 +124,30 @@
"pino-pretty": "^11.2.2",
"poolifier": "^4.2.11",
"preview-email": "^3.1.0",
"prom-client": "^15.1.3",
"prom-client": "14.0.0",
"qrcode": "^1.5.4",
"reflect-metadata": "0.2.2",
"rxjs": "^7.8.1",
"sharp": "^0.33.5",
"socket.io": "^4.8.0",
"stripe": "^16.12.0",
"stripe": "14.19.0",
"swagger-stats": "^0.99.7",
"twilio": "5.3.1",
"unprofane": "^1.0.6",
"url-minify": "^2.8.4"
},
"devDependencies": {
"@antfu/eslint-config": "^3.7.1",
"@antfu/eslint-config": "^3.7.3",
"@firebase/app-compat": "^0.2.41",
"@firebase/app-types": "^0.9.2",
"@golevelup/ts-jest": "^0.5.5",
"@golevelup/ts-jest": "^0.5.6",
"@mikro-orm/cli": "6.3.10",
"@mikro-orm/seeder": "6.3.10",
"@nestjs/cli": "10.4.5",
"@nestjs/schematics": "10.1.4",
"@nestjs/testing": "10.4.3",
"@rubiin/tsconfig": "^1.2.1",
"@sentry/types": "^8.31.0",
"@sentry/types": "^8.32.0",
"@side/jest-runtime": "^1.1.0",
"@swc/core": "^1.7.26",
"@swc/jest": "^0.2.36",
Expand All @@ -159,7 +159,7 @@
"@types/jest": "^29.5.13",
"@types/mime-types": "^2.1.4",
"@types/multer": "^1.4.12",
"@types/node": "^22.6.1",
"@types/node": "^22.7.4",
"@types/nodemailer": "^6.4.16",
"@types/passport": "^1.0.16",
"@types/passport-facebook": "^3.0.3",
Expand All @@ -185,7 +185,7 @@
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "^5.6.2",
"webpack": "^5.94.0",
"webpack": "^5.95.0",
"webpack-node-externals": "^3.0.0"
},
"mikro-orm": {
Expand Down
Loading

0 comments on commit f50be77

Please sign in to comment.