mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
daysbooked in timezone Europe/Berlin
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import * as mongoose from 'mongoose'
|
import * as mongoose from 'mongoose'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { dateFormatBackend, getDays } from '../helpers/date'
|
import { dateFormatBackend, getDays, nowInTz } from '../helpers/date'
|
||||||
import { Bill } from './bill'
|
import { Bill } from './bill'
|
||||||
import { Booker } from './booker'
|
import { Booker } from './booker'
|
||||||
import { BOOKING_STATUS } from './enums'
|
import { BOOKING_STATUS } from './enums'
|
||||||
@@ -89,12 +89,13 @@ BookingSchema.pre('save', function (next) {
|
|||||||
|
|
||||||
BookingSchema.static('findBookedDays', async function (): Promise<string[]> {
|
BookingSchema.static('findBookedDays', async function (): Promise<string[]> {
|
||||||
const model = this as BookingModel
|
const model = this as BookingModel
|
||||||
|
const now = nowInTz()
|
||||||
const bookedDays = await model
|
const bookedDays = await model
|
||||||
.find(
|
.find(
|
||||||
{
|
{
|
||||||
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
|
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
|
||||||
// dateFormatBackend uses YYYY-MM-DD, which is startOfDay anyway
|
// dateFormatBackend uses YYYY-MM-DD, which is startOfDay anyway
|
||||||
endDate: { $gt: dateFormatBackend(new Date()) },
|
endDate: { $gt: dateFormatBackend(now) },
|
||||||
},
|
},
|
||||||
'days'
|
'days'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { parse, format, addDays } from 'date-fns'
|
import { parse, format, addDays } from 'date-fns'
|
||||||
|
import { utcToZonedTime } from 'date-fns-tz'
|
||||||
|
|
||||||
const FRONTEND_FORMAT = 'dd.MM.yyyy'
|
const FRONTEND_FORMAT = 'dd.MM.yyyy'
|
||||||
const BACKEND_FORMAT = 'yyyy-MM-dd'
|
const BACKEND_FORMAT = 'yyyy-MM-dd'
|
||||||
@@ -66,3 +67,8 @@ function dateParse(input: string, formatString: string) {
|
|||||||
export function dateParseFrontend(input: string) {
|
export function dateParseFrontend(input: string) {
|
||||||
return dateParse(input, FRONTEND_FORMAT)
|
return dateParse(input, FRONTEND_FORMAT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function nowInTz(timezone = 'Europe/Berlin') {
|
||||||
|
const now = new Date()
|
||||||
|
return utcToZonedTime(now, timezone)
|
||||||
|
}
|
||||||
|
|||||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -4478,6 +4478,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz",
|
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz",
|
||||||
"integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ=="
|
"integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ=="
|
||||||
},
|
},
|
||||||
|
"date-fns-tz": {
|
||||||
|
"version": "1.0.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-1.0.12.tgz",
|
||||||
|
"integrity": "sha512-Ca+9pjGkU90XDHnclfSjz9o7g/ZqyYyYI0aCYmbf65P75oy8gktuaRslO3UPXl3ADgAnF9/KCykQkpU3/xvtWQ=="
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"date-fns": "^2.16.1",
|
"date-fns": "^2.16.1",
|
||||||
|
"date-fns-tz": "^1.0.12",
|
||||||
"ics": "^2.26.1",
|
"ics": "^2.26.1",
|
||||||
"mongoose": "^5.10.13",
|
"mongoose": "^5.10.13",
|
||||||
"next": "^10.0.1",
|
"next": "^10.0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user