Update calendar with multi-select
This commit is contained in:
@@ -62,3 +62,42 @@ export function getMonthName(date: Date): string {
|
||||
const formatter = new Intl.DateTimeFormat('sv-SE', { month: 'long' })
|
||||
return formatter.format(date)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ISO week number (1-53) for a date.
|
||||
* ISO-8601: Monday-first, week 1 = contains the year's first Thursday.
|
||||
*/
|
||||
export function getISOWeekNumber(date: Date): number {
|
||||
if (!isValidDate(date)) return 0
|
||||
|
||||
const d = new Date(date.getTime())
|
||||
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7))
|
||||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1))
|
||||
const weekNum = Math.ceil((((d.getTime() - yearStart.getTime()) / 86400000) + 1) / 7)
|
||||
|
||||
return weekNum
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all dates in a range (inclusive, ascending order, order-independent).
|
||||
* Dates should be ISO strings (YYYY-MM-DD).
|
||||
*/
|
||||
export function datesInRange(startStr: string, endStr: string): string[] {
|
||||
const start = parseInputDate(startStr)
|
||||
const end = parseInputDate(endStr)
|
||||
|
||||
if (!isValidDate(start) || !isValidDate(end)) {
|
||||
return []
|
||||
}
|
||||
|
||||
const [first, second] = start <= end ? [start, end] : [end, start]
|
||||
const result: string[] = []
|
||||
const current = new Date(first)
|
||||
|
||||
while (current <= second) {
|
||||
result.push(formatDateForInput(current))
|
||||
current.setUTCDate(current.getUTCDate() + 1)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
export function getColorForType(type: string): string {
|
||||
const colorMap: Record<string, string> = {
|
||||
vacation: '#4CAF50',
|
||||
sjukpenning: '#FF9800',
|
||||
lagsta: '#2196F3',
|
||||
}
|
||||
return colorMap[type] ?? '#9E9E9E'
|
||||
}
|
||||
|
||||
export function getLabelForType(type: string): string {
|
||||
const labelMap: Record<string, string> = {
|
||||
vacation: 'Vacation',
|
||||
sjukpenning: 'Sick Leave',
|
||||
lagsta: 'Parental',
|
||||
}
|
||||
return labelMap[type] ?? 'Unknown'
|
||||
}
|
||||
Reference in New Issue
Block a user