update code ngu

This commit is contained in:
2024-11-25 22:06:47 +07:00
parent 84a09375da
commit 26dd46c7a0
7 changed files with 489 additions and 56 deletions

View File

@@ -142,4 +142,19 @@ export class DateTimeUtils {
static getTimeFromDateTime(dateTime: DateTime): TimeType {
return this.toTime(`${dateTime.hour}:${dateTime.minute}:${dateTime.second}`)
}
static subtractDaysFromTimeframe(timeframe: string): DateTime {
// convert timeframe to number of days: 'day' -> 1, 'week' -> 7, 'month' -> 30, 'year' -> 365
const daysMap: Record<string, number> = {
day: 1,
week: 7,
month: 30,
year: 365,
}
const days = daysMap[timeframe.toLowerCase()]
if (days === undefined) {
throw new Error(`Invalid timeframe: ${timeframe}`)
}
return DateTime.now().minus({ days })
}
}