Skip to main content

Dates Plugin

The Dates plugin provides day-of-week filtering for date generation, useful for business logic that depends on weekdays or weekends.

Weekday Dates

Generate dates that fall on weekdays (Monday-Friday):

schema Meeting {
// Only Monday-Friday
scheduled_date: date.weekday(2024, 2025)
}

Weekend Dates

Generate dates that fall on weekends (Saturday-Sunday):

schema Event {
// Only Saturday-Sunday
party_date: date.weekend(2024, 2025)
}

Specific Day of Week

Generate dates for a specific day (0=Sunday through 6=Saturday):

schema Recurring {
// Only Mondays
monday_meeting: date.dayOfWeek(1, 2024, 2025),

// Only Fridays
friday_review: date.dayOfWeek(5, 2024, 2025),

// Only Sundays
sunday_brunch: date.dayOfWeek(0, 2024, 2025)
}

Day numbers:

DayNumber
Sunday0
Monday1
Tuesday2
Wednesday3
Thursday4
Friday5
Saturday6

ISO Date Ranges

Use ISO date strings instead of year numbers:

schema Q1Meeting {
// Weekdays in Q1 2024
date: date.weekday("2024-01-01", "2024-03-31")
}

schema SummerWeekend {
// Weekends in summer 2024
date: date.weekend("2024-06-01", "2024-08-31")
}

Shorthand Syntax

These functions also work without the date. prefix:

schema Meeting {
weekday_meeting: weekday(2024, 2025),
weekend_event: weekend(2024, 2025)
}

Practical Examples

Business Meetings

schema BusinessMeeting {
id: uuid(),
title: faker.company.buzzPhrase(),

// Meetings only on weekdays
scheduled_date: date.weekday(2024, 2025),

// Between 9 AM and 5 PM
start_hour: int in 9..16,

duration_minutes: 30 | 60 | 90
}

Shift Scheduling

schema Shift {
employee: any of employees,

// Day shifts on weekdays
date: date.weekday(2024, 2024),
type: "morning" | "afternoon" | "evening",

// Weekend premium
is_weekend: false
}

schema WeekendShift {
employee: any of employees,

// Weekend shifts only
date: date.weekend(2024, 2024),
type: "day" | "night",

// Weekend premium
is_weekend: true,
premium_rate: 1.5
}

Recurring Events

schema WeeklyStandup {
// Every Monday
date: date.dayOfWeek(1, 2024, 2024),
time: "09:00",
duration: 15,
title: "Daily Standup"
}

schema BiWeeklyReview {
// Every other Friday
date: date.dayOfWeek(5, 2024, 2024),
time: "14:00",
duration: 60,
title: "Sprint Review"
}

Delivery Windows

schema Delivery {
order: any of orders,

// Deliveries only on weekdays
delivery_date: date.weekday(2024, 2024),

// Morning or afternoon slot
time_slot: "morning" | "afternoon",

assume delivery_date >= order.created_date
}

Combining with Constraints

schema Appointment {
type: "regular" | "urgent",

// Regular appointments on weekdays only
date: type == "regular" ?
date.weekday(2024, 2025) :
date in 2024..2025, // Urgent can be any day

time: int in 9..17
}

See Also