update code ngu
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user