date
a set of date formatting methods
object date;
Details
The date object provides the following methods:
-
add ( date, number, unit) - adds/subtracts the specified time interval to/from the date
- date - (Date) the date object that you need to add a time to/subtract a time from
- number - (number) the number of units to add. If this number is positive - the time will be added to the date, if negative - the time will be subtracted
- unit - ('minute', 'hour', 'day', 'week', 'month', 'year') the time unit
//adds 1 year to the specified date: 29 June, 2019 -> 29 June, 2020
var newDate = gantt.date.add(new Date(2019, 05, 29), 1, 'year');
convert_to_utc ( date) - converts local time to UTC
- date - (Date) the date object to convert
//29 June, 2019 14:00 (local time) -> 29 June, 2019 12:00 (utc)
var time = gantt.date.convert_to_utc(new Date(2019, 05, 29, 14, 00));
copy ( date) - makes a copy of a Date object
- date - (Date) the date object to copy
var copy = gantt.date.copy(new Date(2019, 05, 29));// -> 29 June, 2019
date_part ( date) - resets the time part of the provided date to 00:00:00
- date - (Date) the date object to format
//29 June, 2019 14:30:10 -> 29 June, 2019 00:00:00
var date = gantt.date.date_part(new Date(2019, 05, 29, 14, 30, 10));
date_to_str ( format, utc) - returns a function that converts a Date object to a string of the specified format
- format - (string) the date format ( see Date Format Specification)
- utc - (boolean) specifies whether local time should be converted to UTC
var formatFunc = gantt.date.date_to_str("%d/%m/%Y");
var date = formatFunc(new Date(2019, 05, 29)); // -> "29/06/2019"
day_start ( date) - resets the time part of the provided date to 00:00:00. Alias of the date_part method. Used by the Day view to set the display date and can be redefined to provide the default behaviour
- date - (Date) the date object to format
//29 June, 2013 14:30:10 -> 29 June, 2019 00:00:00
var date = gantt.date.day_start(new Date(2019, 05, 29, 14, 30, 10));
getISOWeek ( date) - returns the ISO-8601 week number of the date, weeks starts on Monday
- date - (Date) the date object to format
var week = gantt.date.getISOWeek(new Date(2019, 05, 29));// ->26
getUTCISOWeek ( date) - returns the week number of the date, but previously converts local time to UTC
- date - (Date) the date object to format
var week = gantt.date.getUTCISOWeek(new Date(2019, 05, 29));// ->26
getWeek ( date) - returns the week number of the date. Weeks start either on Monday or Sunday, depending on the value of the start_on_monday property.
- date - (Date) the date object to format
// weeks start on Sunday
gantt.config.start_on_monday = false;
var isoWeek = gantt.date.getISOWeek(new Date(2019, 2, 25)); // ->12
var week = gantt.date.getWeek(new Date(2019, 2, 25)); // ->13
month_start ( date) - returns a Date object of the first day of the month for the specified date and clears the time part to zero
- date - (Date) the date object to format
//29 June, 2019 14:30 -> 01 June, 2019 00:00
var firstDay = gantt.date.month_start(new Date(2019, 05, 29, 14, 30));
parseDate ( date, format) - converts a string of the specified format to a Date object
var date = gantt.date.parseDate("29/06/2019","%d/%m/%Y");//-> 29 June, 2019 00:00:00
str_to_date ( format, utc) - returns a function that converts a string of the specified format to a Date object
- format - (string) the date format ( see Date Format Specification)
- utc - (boolean) specifies whether local time should be converted to UTC
var formatFunc = gantt.date.str_to_date("%d/%m/%Y");
var date = formatFunc("29/06/2019"); // -> 29 June, 2019 00:00:00
time_part ( date) - returns the time of a Date object as a number of seconds counted from the midnight (00:00:00)
- date - (Date) the date object to format
var time = gantt.date.time_part(new Date(2019, 05, 29, 14, 30, 10));
to_fixed ( num) - adds the leading zero to numbers less than 10 and returns the result as a string. Doesn't affect numbers from 10
- num - (number) the number to format
var num1 = gantt.date.to_fixed(2);// ->"02"
var num2 = gantt.date.to_fixed(10);// ->10
week_start ( date) - returns a Date object of the first day of the week for the specified date and clears the time part to zero
- date - (Date) the date object to format
//29 June, 2019 14:30 -> 24 June, 2019 00:00
var weekStart = gantt.date.week_start(new Date(2019, 05, 29, 14, 30));
year_start ( date) - returns a Date object of the first day of the year for the specified date and clears the time part to zero
- date - (Date) the date object to format
//29 June, 2019 14:30 -> 01 January, 2019 00:00
var yearStart = gantt.date.year_start(new Date(2019, 05, 29, 14, 30));
Back to top