@@ -243,3 +243,140 @@ datetime_object
243
243
- 1970-01-01T03:00:00.125+0300
244
244
...
245
245
246
+ .. _datetime-add :
247
+
248
+ .. method :: add( { input[, adjust ] } )
249
+
250
+ Modify an existing datetime object by adding values of the input argument. [TBD]
251
+
252
+ :param table input: an :ref: `interval object <interval-new >` or an equivalent table (see **Example #1 **)
253
+ :param string adjust: defines how to round days in a month after an arithmetic operation.
254
+ Possible values: ``none ``, ``last ``, ``excess `` (see **Example #2 **). Defaults to ``none ``.
255
+
256
+ :return: datetime_object
257
+ :rtype: cdata
258
+
259
+ **Example #1: **
260
+
261
+ .. code-block :: tarantoolsession
262
+
263
+ tarantool> dt = datetime.new {
264
+ day = 26,
265
+ month = 8,
266
+ year = 2021,
267
+ tzoffset = 180
268
+ }
269
+ ---
270
+ ...
271
+
272
+ tarantool> iv = datetime.interval.new {day = 7}
273
+ ---
274
+ ...
275
+
276
+ tarantool> dt, iv
277
+ ---
278
+ - 2021-08-26T00:00:00+0300
279
+ - +7 days
280
+ ...
281
+
282
+ tarantool> dt:add(iv)
283
+ ---
284
+ - 2021-09-02T00:00:00+0300
285
+ ...
286
+
287
+ tarantool> dt:add{ day = 7 }
288
+ ---
289
+ - 2021-09-09T00:00:00+0300
290
+ ...
291
+
292
+ .. _datetime-add-example2 :
293
+
294
+ **Example #2: **
295
+
296
+ .. code-block :: tarantoolsession
297
+
298
+ tarantool> dt = datetime.new {
299
+ day = 29,
300
+ month = 2,
301
+ year = 2020
302
+ }
303
+ ---
304
+ ...
305
+
306
+ tarantool> dt:add{month = 1, adjust = 'none'}
307
+ ---
308
+ - 2020-03-29T00:00:00Z
309
+ ...
310
+
311
+ tarantool> dt = datetime.new {
312
+ day = 29,
313
+ month = 2,
314
+ year = 2020
315
+ }
316
+ ---
317
+ ...
318
+
319
+ tarantool> dt:add{month = 1, adjust = 'last'}
320
+ ---
321
+ - 2020-03-31T00:00:00Z
322
+ ...
323
+
324
+ tarantool> dt = datetime.new {
325
+ day = 31,
326
+ month = 1,
327
+ year = 2020
328
+ }
329
+ ---
330
+ ...
331
+
332
+ tarantool> dt:add{month = 1, adjust = 'exсess'}
333
+ ---
334
+ - 2020-03-02T00:00:00Z
335
+ ...
336
+
337
+ .. _datetime-sub :
338
+
339
+ .. method :: sub( { input[, adjust ] } )
340
+
341
+ Modify an existing datetime object by subtracting values of the input argument. [TBD]
342
+
343
+ :param table input: an :ref: `interval object <interval-new >` or an equivalent table (see **Example **)
344
+ :param string adjust: defines how to round days in a month after an arithmetic operation.
345
+ Possible values: ``none ``, ``last ``, ``excess ``. Defaults to ``none ``.
346
+ The logic is similar to the one of the ``:add() `` method -- see :ref: `Example #2 <datetime-add-example2 >`. [TBD]
347
+
348
+ :return: datetime_object
349
+ :rtype: cdata
350
+
351
+ **Example: **
352
+
353
+ .. code-block :: tarantoolsession
354
+
355
+ tarantool> dt = datetime.new {
356
+ day = 26,
357
+ month = 8,
358
+ year = 2021,
359
+ tzoffset = 180
360
+ }
361
+ ---
362
+ ...
363
+
364
+ tarantool> iv = datetime.interval.new {day = 5}
365
+ ---
366
+ ...
367
+
368
+ tarantool> dt, iv
369
+ ---
370
+ - 2021-08-26T00:00:00+0300
371
+ - +5 days
372
+ ...
373
+
374
+ tarantool> dt:sub(iv)
375
+ ---
376
+ - 2021-08-21T00:00:00+0300
377
+ ...
378
+
379
+ tarantool> dt:sub{ day = 1 }
380
+ ---
381
+ - 2021-08-20T00:00:00+0300
382
+ ...
0 commit comments