Opened 13 years ago

Closed 6 years ago

#9021 closed enhancement (patchwelcome)

Date Utils: Truncate Date

Reported by: Jarrod Carlson Owned by: Adam Peller
Priority: high Milestone: 1.13
Component: Dojox Version:
Keywords: date utils Cc: Nathan Toone, mde
Blocked By: Blocking:


Attached is a new module that I started to provide some additional Date utility functionality that I have not found in Dojo. I'm sure this can expand, but I'm using it to allow a Date object to be truncated, similar to what is provided by the Commons Lang DateUtils? in Java (

Though the contract differs somewhat from Commons Lang, I found good use in being able to selectively truncate a Date's parts.

To truncate a a Date, do:

  var t =,;

The truncation is performs using a bitmask for the fields to truncate.


Attachments (1)

utils.js (1.5 KB) - added by Jarrod Carlson 13 years ago.

Download all attachments as: .zip

Change History (9)

Changed 13 years ago by Jarrod Carlson

Attachment: utils.js added

comment:1 Changed 12 years ago by dante

Cc: Adam Peller added

@peller, you are the resident date expert ... comments?

comment:2 Changed 12 years ago by Jarrod Carlson

I actually discovered a slight bug in this code which I have yet to come up with a good solution.

I'm not sure if I would consider it a bug or "by design" but it is worth noting.

If you have a date of Feb. 29 in a leap year and you try to truncate the year (1970 is not a leap year), The date will roll over to March 1st in that case.

Perhaps the best way to address this would be to truncate the date object to the precision you specify, and no less. So do not allow truncation of the hour without also truncating the minute, second and millisecond.


comment:3 Changed 12 years ago by Adam Peller

Milestone: tbd1.5

I'm a little leery of anything involving native Date objects at this point :) We could commit this as experimental to and work on it there, if you'd be willing to maintain it. One thing that jumps out -- can we use strings instead of enum style args, like does?

I think I encountered something similar to your leap month problem in and we used Jan 1 1972 for our computations, or something like that.

comment:4 Changed 12 years ago by Adam Peller

Cc: Nathan Toone added; Adam Peller removed
Component: CoreDojox
Owner: changed from anonymous to Adam Peller

comment:5 Changed 12 years ago by Adam Peller

Cc: mde added

comment:6 Changed 12 years ago by Adam Peller

Milestone: 1.51.6

comment:7 Changed 11 years ago by Adam Peller

Milestone: 1.6future

comment:8 Changed 6 years ago by dylan

Milestone: future1.12
Resolution: patchwelcome
Status: newclosed

Given that no one has shown interest in creating a patch in the past 5+ years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.