META-INF.resources.bower_components.globalize.src.date.start-of.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jwebmp-globalize Show documentation
Show all versions of jwebmp-globalize Show documentation
The JWebSwing implementation for a full Globalization
The newest version!
define(function () {
/**
* startOf changes the input to the beginning of the given unit.
*
* For example, starting at the start of a day, resets hours, minutes
* seconds and milliseconds to 0. Starting at the month does the same, but
* also sets the date to 1.
*
* Returns the modified date
*/
return function (date, unit) {
date = new Date(date.getTime());
switch (unit) {
case "year":
date.setMonth(0);
/* falls through */
case "month":
date.setDate(1);
/* falls through */
case "day":
date.setHours(0);
/* falls through */
case "hour":
date.setMinutes(0);
/* falls through */
case "minute":
date.setSeconds(0);
/* falls through */
case "second":
date.setMilliseconds(0);
}
return date;
};
});