Update of DP_DateExtensions to add First-Day-of-Week Option

A slight update to my JavaScript date extensions, DP_DateExtensions, is now available for download.  This release adds the ability to specify which day of week is considered the first day of the week when using the date math functions.  (Thanks to Neil Cresswell of cresswell.net for suggesting this addition.)

JavaScript itself considers Sunday (denoted as zero) the first day of the week by default.  This update provides access to a new property of the Date object, Date.FirstDayOfWeek, that can be set to any day from Sunday (zero) to Saturday (six).  This setting will then affect date math in the  round(), ceil(), floor() and diff() functions when the specified date part is “weeks”.

     // Set first day of week to Monday ("1")
Date.FirstDayOfWeek = 1
     // Create a new date
CurDate = new Date();
     // Perform some date math
RoundedWeek = CurDate.round("weeks");
FloorWeek = CurDate.floor("weeks")
CeilWeek = CurDate.ceil("weeks")

Personally I’ve not needed to leverage this yet, but I can definitely see it coming in handy.

Leave a Reply