From 5af437b5bb628a12caee91ce244e8e8364a6d381 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 21 Apr 2016 13:31:12 +0200 Subject: [PATCH] Add documentation for the DateTime type fixes #9839 --- doc/19-library-reference.md | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/doc/19-library-reference.md b/doc/19-library-reference.md index 8fffb8288..0f0eed85f 100644 --- a/doc/19-library-reference.md +++ b/doc/19-library-reference.md @@ -757,6 +757,8 @@ Returns a list of keys for all items that are currently in the dictionary. ## Function type +Inherits methods from the [Object type](19-library-reference.md#object-type). + ### Function#call Signature: @@ -797,3 +799,68 @@ Example: set_x.callv(dict, args) /* Invokes set_x using `dict` as `this` */ +## DateTime type + +Inherits methods from the [Object type](19-library-reference.md#object-type). + +### DateTime constructor + +Signature: + + function DateTime() + function DateTime(unixTimestamp) + function DateTime(year, month, day) + function DateTime(year, month, day, hours, minutes, seconds) + +Constructs a new DateTime object. When no arguments are specified for the constructor a new +DateTime object representing the current time is created. + +Example: + + var d1 = DateTime() /* current time */ + var d2 = DateTime(2016, 5, 21) /* midnight April 21st, 2016 (local time) */ + +### DateTime arithmetic + +Subtracting two DateTime objects yields the interval between them, in seconds. + +Example: + + var delta = DateTime() - DateTime(2016, 5, 21) /* seconds since midnight April 21st, 2016 */ + +Subtracting a number from a DateTime object yields a new DateTime object that is further in the past: + +Example: + + var dt = DateTime() - 2 * 60 * 60 /* Current time minus 2 hours */ + +Adding a number to a DateTime object yields a new DateTime object that is in the future: + +Example: + + var dt = DateTime() + 24 * 60 60 /* Current time plus 24 hours */ + +### DateTime#format + +Signature: + + function format(fmt) + +Returns a string representation for the DateTime object using the specified format string. +The format string may contain format conversion placeholders as specified in strftime(3). + +Example: + + var s = DateTime(2016, 4, 21).format("%A") /* Sets s to "Thursday". */ + +### DateTime#to_string + +Signature: + + function to_string() + +Returns a string representation for the DateTime object. Uses a suitable default format. + +Example: + + var s = DateTime(2016, 4, 21).to_string() /* Sets s to "2016-04-21 00:00:00 +0200". */