Overview
The WeekDay plugin adds locale-aware week functionality to Atemporal. It allows you to set the start of the week and provides methods that respect that setting, making it easy to work with different calendar systems and locales.Installation
Using extend()
Using lazyLoad()
Configuration
setWeekStartsOn()
Sets the global start of the week for all atemporal instances.day- The day to set as the start of the week0= Sunday1= Monday (ISO 8601 standard)2= Tuesday3= Wednesday4= Thursday5= Friday6= Saturday
Instance Methods
weekday()
Gets the day of the week according to the locale’s configured start day.number - Day of the week (0-6) relative to the configured week start
Example:
startOf(‘week’)
Returns a new instance set to the start of the week, respecting the locale’s configured start day.unit- Must be'week'for week-aware behavior
TemporalWrapper - New instance at the start of the week
Example:
endOf(‘week’)
Returns a new instance set to the end of the week, respecting the locale’s configured start day.unit- Must be'week'for week-aware behavior
TemporalWrapper - New instance at the end of the week (last millisecond)
Example:
Performance Features
The WeekDay plugin includes built-in caching for improved performance:- Weekday Cache: Caches weekday calculations (100 entries)
- Week Boundary Cache: Caches week start/end computations (50 entries)
- LRU Eviction: Automatically removes least recently used entries
Cache Management
Complete Example
Localization Support
The plugin works seamlessly with different locale conventions:Notes
- The plugin enhances existing
startOf()andendOf()methods for the'week'unit - Other units (
'year','month','day', etc.) work as usual - The configuration is global and affects all atemporal instances
- Invalid dates return
NaNforweekday()and the original instance forstartOf()/endOf() - The plugin uses internal caching for optimal performance with repeated calculations