Skip to content

Commit 010ad92

Browse files
Merge pull request #80 from mlakatkou/GS-3320
[update] date article
2 parents 14d139a + 38c7913 commit 010ad92

1 file changed

Lines changed: 68 additions & 68 deletions

File tree

docs/api/other/date.md

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ description: "A set of date formatting methods"
1515

1616
### Methods
1717

18-
#### add(date, number, unit)
18+
#### `add(date, number, unit)`
1919
Adds/subtracts the specified time interval to/from the date
2020

2121
**Parameters**:
2222
- `date` - (Date) - The date object
2323
- `number` - (number) - Number of units to add (positive) or subtract (negative)
24-
- `unit` - (string) - Time unit: 'minute', 'hour', 'day', 'week', 'month', 'year'
24+
- `unit` - (string) - Time unit: `minute`, `hour`, `day`, `week`, `month`, `year`
2525

2626
**Returns**: Date - The new date object
2727

2828
**Example**:
2929
~~~js
30-
// adds 1 year to the specified date: 29 June, 2019 -> 29 June, 2020
31-
var newDate = gantt.date.add(new Date(2019, 05, 29), 1, 'year');
30+
// adds 1 year to the specified date: 29 June, 2027 -> 29 June, 2028
31+
const newDate = gantt.date.add(new Date(2027, 5, 29), 1, 'year');
3232
~~~
3333

3434
---
3535

36-
#### add_quarter(date, number)
36+
#### `add_quarter(date, number)`
3737
Adds/subtracts the specified number of quarters to/from the date
3838

3939
**Parameters**:
@@ -45,13 +45,13 @@ Adds/subtracts the specified number of quarters to/from the date
4545
**Example**:
4646
~~~js
4747
// adds 1 quarter (3 months) to the specified date:
48-
// 29 June, 2019 -> 29 September, 2020
49-
var newDate = gantt.date.add_quarter(new Date(2019, 05, 29), 1);
48+
// 29 June, 2027 -> 29 September, 2027
49+
const newDate = gantt.date.add_quarter(new Date(2027, 5, 29), 1);
5050
~~~
5151

5252
---
5353

54-
#### convert_to_utc(date)
54+
#### `convert_to_utc(date)`
5555
Converts local time to UTC
5656

5757
**Parameters**:
@@ -61,13 +61,13 @@ Converts local time to UTC
6161

6262
**Example**:
6363
~~~js
64-
// 29 June, 2019 14:00 (local time) -> 29 June, 2019 12:00 (utc)
65-
var time = gantt.date.convert_to_utc(new Date(2019, 05, 29, 14, 00));
64+
// 29 June, 2027 14:00 (local time) -> 29 June, 2027 12:00 (utc)
65+
const utcTime = gantt.date.convert_to_utc(new Date(2027, 5, 29, 14, 0));
6666
~~~
6767

6868
---
6969

70-
#### copy(date)
70+
#### `copy(date)`
7171
Makes a copy of a Date object
7272

7373
**Parameters**:
@@ -77,12 +77,12 @@ Makes a copy of a Date object
7777

7878
**Example**:
7979
~~~js
80-
var copy = gantt.date.copy(new Date(2019, 05, 29)); // -> 29 June, 2019
80+
const copiedDate = gantt.date.copy(new Date(2027, 5, 29)); // -> 29 June, 2027
8181
~~~
8282

8383
---
8484

85-
#### date_part(date)
85+
#### `date_part(date)`
8686
Resets the time part of the provided date to 00:00:00
8787

8888
**Parameters**:
@@ -92,31 +92,31 @@ Resets the time part of the provided date to 00:00:00
9292

9393
**Example**:
9494
~~~js
95-
// 29 June, 2019 14:30:10 -> 29 June, 2019 00:00:00
96-
var date = gantt.date.date_part(new Date(2019, 05, 29, 14, 30, 10));
95+
// 29 June, 2027 14:30:10 -> 29 June, 2027 00:00:00
96+
const dateWithoutTime = gantt.date.date_part(new Date(2027, 5, 29, 14, 30, 10));
9797
~~~
9898

9999
---
100100

101-
#### date_to_str(format, utc)
101+
#### `date_to_str(format, utc)`
102102
Returns a function that converts a Date object to a string of the specified format
103103

104104
**Parameters**:
105-
- `format` - (string) - The date format (see guides/date-format.md)
105+
- `format` - (string) - The date format (see [Date Format Specification](guides/date-format.md))
106106
- `utc` - (boolean, optional) - Whether to convert to UTC
107107

108108
**Returns**: Function - The formatting function
109109

110110
**Example**:
111111
~~~js
112-
var formatFunc = gantt.date.date_to_str("%d/%m/%Y");
113-
var date = formatFunc(new Date(2019, 05, 29)); // -> "29/06/2019"
112+
const formatDate = gantt.date.date_to_str("%d/%m/%Y");
113+
const formattedDate = formatDate(new Date(2027, 5, 29)); // -> "29/06/2027"
114114
~~~
115115

116116
---
117117

118-
#### day_start(date)
119-
Resets the time part of the provided date to 00:00:00 (alias of date_part)
118+
#### `day_start(date)`
119+
Resets the time part of the provided date to 00:00:00 (alias of `date_part()`)
120120

121121
**Parameters**:
122122
- `date` - (Date) - The date object to format
@@ -125,13 +125,13 @@ Resets the time part of the provided date to 00:00:00 (alias of date_part)
125125

126126
**Example**:
127127
~~~js
128-
// 29 June, 2019 14:30:10 -> 29 June, 2019 00:00:00
129-
var date = gantt.date.day_start(new Date(2019, 05, 29, 14, 30, 10));
128+
// 29 June, 2027 14:30:10 -> 29 June, 2027 00:00:00
129+
const dayStart = gantt.date.day_start(new Date(2027, 5, 29, 14, 30, 10));
130130
~~~
131131

132132
---
133133

134-
#### getISOWeek(date)
134+
#### `getISOWeek(date)`
135135
Returns the ISO-8601 week number of the date (weeks start on Monday)
136136

137137
**Parameters**:
@@ -141,12 +141,12 @@ Returns the ISO-8601 week number of the date (weeks start on Monday)
141141

142142
**Example**:
143143
~~~js
144-
var week = gantt.date.getISOWeek(new Date(2019, 05, 29)); // ->26
144+
const isoWeek = gantt.date.getISOWeek(new Date(2027, 5, 29)); // ->26
145145
~~~
146146

147147
---
148148

149-
#### getUTCISOWeek(date)
149+
#### `getUTCISOWeek(date)`
150150
Returns the week number of the date after converting to UTC
151151

152152
**Parameters**:
@@ -156,13 +156,13 @@ Returns the week number of the date after converting to UTC
156156

157157
**Example**:
158158
~~~js
159-
var week = gantt.date.getUTCISOWeek(new Date(2019, 05, 29)); // ->26
159+
const utcIsoWeek = gantt.date.getUTCISOWeek(new Date(2027, 5, 29)); // ->26
160160
~~~
161161

162162
---
163163

164-
#### getWeek(date)
165-
Returns the week number of the date (week start depends on gantt.config.start_on_monday)
164+
#### `getWeek(date)`
165+
Returns the week number of the date (week start depends on `gantt.config.start_on_monday`)
166166

167167
**Parameters**:
168168
- `date` - (Date) - The date object
@@ -174,13 +174,13 @@ Returns the week number of the date (week start depends on gantt.config.start_on
174174
// weeks start on Sunday
175175
gantt.config.start_on_monday = false;
176176

177-
var isoWeek = gantt.date.getISOWeek(new Date(2019, 2, 25)); // ->12
178-
var week = gantt.date.getWeek(new Date(2019, 2, 25)); // ->13
177+
const isoWeek = gantt.date.getISOWeek(new Date(2027, 2, 25)); // ->12
178+
const week = gantt.date.getWeek(new Date(2027, 2, 25)); // ->13
179179
~~~
180180

181181
---
182182

183-
#### month_start(date)
183+
#### `month_start(date)`
184184
Returns the first day of the month with time reset to 00:00:00
185185

186186
**Parameters**:
@@ -190,15 +190,15 @@ Returns the first day of the month with time reset to 00:00:00
190190

191191
**Example**:
192192
~~~js
193-
// 29 June, 2019 14:30 -> 01 June, 2019 00:00
194-
var firstDay = gantt.date.month_start(new Date(2019, 05, 29, 14, 30));
193+
// 29 June, 2027 14:30 -> 01 June, 2027 00:00
194+
const firstDayOfMonth = gantt.date.month_start(new Date(2027, 5, 29, 14, 30));
195195
~~~
196196

197197
---
198198

199-
#### parseDate(date, format)
199+
#### `parseDate(date, format)`
200200

201-
Converts a date string to a Date object. This method is called during [gantt.load()](api/method/load.md) and [gantt.parse()](api/method/parse.md) to parse task and link date properties.
201+
Converts a date string to a Date object. This method is called during [`load()`](api/method/load.md) and [`parse()`](api/method/parse.md) to parse task and link date properties.
202202

203203
**Parameters**:
204204
- `date` - (string) - The date string to parse
@@ -208,46 +208,46 @@ Converts a date string to a Date object. This method is called during [gantt.loa
208208

209209
**Parsing logic** (since v9.1.3):
210210

211-
1. **ISO 8601 check** - if the string matches an ISO 8601 pattern (e.g. `"2026-01-06"`, `"2026-01-06T10:30:00Z"`), it is parsed directly and `format` is not consulted. If the user has explicitly overridden `gantt.templates.parse_date`, ISO auto-detection is skipped and the user's function handles all parsing.
212-
2. **`format` argument** - if provided as a string, it is converted to a parser function via `gantt.date.str_to_date(format)`; if provided as a function, it is called directly
213-
3. **Fallback** - if no `format` is provided, the [parse_date](api/template/parse_date.md) template is used
211+
1. **ISO 8601 check** - if the string matches an ISO 8601 pattern (e.g. `"2027-01-06"`, `"2027-01-06T10:30:00Z"`), it is parsed directly and `format` is not consulted. If the user has explicitly overridden the `parse_date` template, ISO auto-detection is skipped and the user's function handles all parsing.
212+
2. **`format` argument** - if provided as a string, it is converted to a parser function via `str_to_date()`; if provided as a function, it is called directly
213+
3. **Fallback** - if no `format` is provided, the [`parse_date`](api/template/parse_date.md) template is used
214214

215215
**Examples**:
216216
~~~js
217217
// with an explicit format string
218-
var date = gantt.date.parseDate("29/06/2019", "%d/%m/%Y");
219-
// -> 29 June, 2019 00:00:00
218+
const parsedDate = gantt.date.parseDate("29/06/2027", "%d/%m/%Y");
219+
// -> 29 June, 2027 00:00:00
220220

221221
// ISO string - parsed automatically, format is ignored
222-
var date2 = gantt.date.parseDate("2026-01-06T10:30:00Z");
223-
// -> 6 January, 2026 10:30:00 UTC
222+
const parsedIsoDate = gantt.date.parseDate("2027-01-06T10:30:00Z");
223+
// -> 6 January, 2027 10:30:00 UTC
224224

225225
// with a custom parser function
226-
var date3 = gantt.date.parseDate("Jan 6, 2026", function(str) {
226+
const parsedCustomDate = gantt.date.parseDate("Jan 6, 2027", (str) => {
227227
return new Date(str);
228228
});
229229
~~~
230230

231231
---
232232

233-
#### str_to_date(format, utc)
233+
#### `str_to_date(format, utc)`
234234
Returns a function that converts a string to a Date object
235235

236236
**Parameters**:
237-
- `format` - (string) - The date format (see guides/date-format.md)
237+
- `format` - (string) - The date format (see [Date Format Specification](guides/date-format.md))
238238
- `utc` - (boolean, optional) - Whether to convert to UTC
239239

240240
**Returns**: Function - The parsing function
241241

242242
**Example**:
243243
~~~js
244-
var formatFunc = gantt.date.str_to_date("%d/%m/%Y");
245-
var date = formatFunc("29/06/2019"); // -> 29 June, 2019 00:00:00
244+
const parseDate = gantt.date.str_to_date("%d/%m/%Y");
245+
const parsedDate = parseDate("29/06/2027"); // -> 29 June, 2027 00:00:00
246246
~~~
247247

248248
---
249249

250-
#### time_part(date)
250+
#### `time_part(date)`
251251
Returns the time as seconds since midnight
252252

253253
**Parameters**:
@@ -257,12 +257,12 @@ Returns the time as seconds since midnight
257257

258258
**Example**:
259259
~~~js
260-
var time = gantt.date.time_part(new Date(2019, 05, 29, 14, 30, 10));
260+
const secondsSinceMidnight = gantt.date.time_part(new Date(2027, 5, 29, 14, 30, 10));
261261
~~~
262262

263263
---
264264

265-
#### to_fixed(num)
265+
#### `to_fixed(num)`
266266
Adds leading zero to numbers < 10
267267

268268
**Parameters**:
@@ -272,13 +272,13 @@ Adds leading zero to numbers < 10
272272

273273
**Example**:
274274
~~~js
275-
var num1 = gantt.date.to_fixed(2); // ->"02"
276-
var num2 = gantt.date.to_fixed(10); // ->10
275+
const paddedNumber = gantt.date.to_fixed(2); // ->"02"
276+
const unchangedNumber = gantt.date.to_fixed(10); // ->10
277277
~~~
278278

279279
---
280280

281-
#### minute_start(date)
281+
#### `minute_start(date)`
282282
Resets seconds to 00
283283

284284
**Parameters**:
@@ -288,13 +288,13 @@ Resets seconds to 00
288288

289289
**Example**:
290290
~~~js
291-
// 29 June, 2019 14:30:10 -> 29 June, 2019 14:30:00
292-
var date = gantt.date.minute_start(new Date(2019, 05, 29, 14, 30, 10));
291+
// 29 June, 2027 14:30:10 -> 29 June, 2027 14:30:00
292+
const minuteStart = gantt.date.minute_start(new Date(2027, 5, 29, 14, 30, 10));
293293
~~~
294294

295295
---
296296

297-
#### hour_start(date)
297+
#### `hour_start(date)`
298298
Resets minutes and seconds to 00
299299

300300
**Parameters**:
@@ -304,13 +304,13 @@ Resets minutes and seconds to 00
304304

305305
**Example**:
306306
~~~js
307-
// 29 June, 2019 14:30:10 -> 29 June, 2019 14:00:00
308-
var date = gantt.date.hour_start(new Date(2019, 05, 29, 14, 30, 10));
307+
// 29 June, 2027 14:30:10 -> 29 June, 2027 14:00:00
308+
const hourStart = gantt.date.hour_start(new Date(2027, 5, 29, 14, 30, 10));
309309
~~~
310310

311311
---
312312

313-
#### week_start(date)
313+
#### `week_start(date)`
314314
Returns the first day of the week with time reset to 00:00:00
315315

316316
**Parameters**:
@@ -320,13 +320,13 @@ Returns the first day of the week with time reset to 00:00:00
320320

321321
**Example**:
322322
~~~js
323-
// 29 June, 2019 14:30 -> 24 June, 2019 00:00
324-
var weekStart = gantt.date.week_start(new Date(2019, 05, 29, 14, 30));
323+
// 29 June, 2027 14:30 -> 28 June, 2027 00:00
324+
const weekStart = gantt.date.week_start(new Date(2027, 5, 29, 14, 30));
325325
~~~
326326

327327
---
328328

329-
#### quarter_start(date)
329+
#### `quarter_start(date)`
330330
Returns the first month of the quarter with time reset to 00:00:00
331331

332332
**Parameters**:
@@ -336,13 +336,13 @@ Returns the first month of the quarter with time reset to 00:00:00
336336

337337
**Example**:
338338
~~~js
339-
// 29 June, 2019 14:30:10 -> 01 April, 2019 00:00:00
340-
var date = gantt.date.quarter_start(new Date(2019, 05, 29, 14, 30, 10));
339+
// 29 June, 2027 14:30:10 -> 01 April, 2027 00:00:00
340+
const quarterStart = gantt.date.quarter_start(new Date(2027, 5, 29, 14, 30, 10));
341341
~~~
342342

343343
---
344344

345-
#### year_start(date)
345+
#### `year_start(date)`
346346
Returns the first day of the year with time reset to 00:00:00
347347

348348
**Parameters**:
@@ -352,6 +352,6 @@ Returns the first day of the year with time reset to 00:00:00
352352

353353
**Example**:
354354
~~~js
355-
// 29 June, 2019 14:30 -> 01 January, 2019 00:00
356-
var yearStart = gantt.date.year_start(new Date(2019, 05, 29, 14, 30));
355+
// 29 June, 2027 14:30 -> 01 January, 2027 00:00
356+
const yearStart = gantt.date.year_start(new Date(2027, 5, 29, 14, 30));
357357
~~~

0 commit comments

Comments
 (0)