Skip to content

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 past
  • isFuture(period, temporal) - Check if period is in the future
  • isYesterday(period, temporal) - Check if period was yesterday
  • isTomorrow(period, temporal) - Check if period is tomorrow
  • isThisWeek(period, temporal) - Check if period is in current week
  • isThisMonth(period, temporal) - Check if period is in current month
  • isThisYear(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),
  }
}

Released under the MIT License.