Utilities
Utility functions for common date-related checks and operations.
Date Check Utilities
isWeekend
Check if a period falls on a weekend (Saturday or Sunday).
typescript
function isWeekend(period: Period): boolean
// Example
if (isWeekend(dayPeriod)) {
console.log('It\'s the weekend!')
}isWeekday
Check if a period falls on a weekday (Monday through Friday).
typescript
function isWeekday(period: Period): boolean
// Example
const businessDays = days.filter(day => isWeekday(day))isToday
Check if a period represents today.
typescript
function isToday(adapter: Adapter, now: Date, period: Period): boolean
// Example
const now = new Date()
if (isToday(adapter, now, dayPeriod)) {
element.classList.add('today')
}Coming Soon
More utility functions are planned:
isPast(period, temporal)- Check if period is in the pastisFuture(period, temporal)- Check if period is in the futureisYesterday(period, temporal)- Check if period was yesterdayisTomorrow(period, temporal)- Check if period is tomorrowisThisWeek(period, temporal)- Check if period is in current weekisThisMonth(period, temporal)- Check if period is in current monthisThisYear(period, temporal)- Check if period is in current year
Usage Example
typescript
import { isWeekend, isWeekday, isToday } from '@allystudio/usetemporal/operations'
import type { Period, Adapter } from '@allystudio/usetemporal'
// In a calendar component
function getDayClasses(day: Period, adapter: Adapter) {
const now = new Date()
return {
'weekend': isWeekend(day),
'weekday': isWeekday(day),
'today': isToday(adapter, now, day),
}
}