From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [RFC PATCH 04/13] test: datetime string formatting Date: Thu, 15 Jul 2021 11:18:10 +0300 [thread overview] Message-ID: <fde3bf22f648bb5d1f3cd830d03dbb230da45944.1626335241.git.tsafin@tarantool.org> (raw) In-Reply-To: <cover.1626335241.git.tsafin@tarantool.org> * Added case to check datetime string formatting using - asctime (gmt time); - ctime (local TZ time); - strftime (using given format). --- test/app-tap/datetime.test.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/app-tap/datetime.test.lua b/test/app-tap/datetime.test.lua index bc66b3296..914371747 100755 --- a/test/app-tap/datetime.test.lua +++ b/test/app-tap/datetime.test.lua @@ -4,7 +4,7 @@ local tap = require('tap') local test = tap.test("errno") local date = require('datetime') -test:plan(2) +test:plan(3) test:test("Simple tests for parser", function(test) test:plan(2) @@ -86,4 +86,30 @@ test:test("Multiple tests for parser (with nanoseconds)", function(test) end end) +local ffi = require('ffi') + +ffi.cdef [[ + void tzset(void); +]] + +test:test("Datetime string formatting", function(test) + test:plan(7) + local str = "1970-01-01" + local t = date(str) + test:ok(t.secs == 0, ('%s: t.secs == %d'):format(str, t.secs)) + test:ok(t.nsec == 0, ('%s: t.nsec == %d'):format(str, t.nsec)) + test:ok(t.offset == 0, ('%s: t.offset == %d'):format(str, t.offset)) + test:ok(date.asctime(t) == 'Thu Jan 1 00:00:00 1970\n', ('%s: asctime'):format(str)) + -- ctime() is local timezone dependent. To make sure that + -- test is deterministic we enforce timezone via TZ environment + -- manipulations and calling tzset() + + -- redefine timezone to be always GMT-2 + os.setenv('TZ', 'GMT-2') + ffi.C.tzset() + test:ok(date.ctime(t) == 'Thu Jan 1 02:00:00 1970\n', ('%s: ctime with timezone'):format(str)) + test:ok(date.strftime('%d/%m/%Y', t) == '01/01/1970', ('%s: strftime #1'):format(str)) + test:ok(date.strftime('%A %d. %B %Y', t) == 'Thursday 01. January 1970', ('%s: strftime #2'):format(str)) +end) + os.exit(test:check() and 0 or 1) -- 2.29.2
next prev parent reply other threads:[~2021-07-15 8:20 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-15 8:18 [Tarantool-patches] [RFC PATCH 00/13] Initial datetime support Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 01/13] build: add Christian Hansen c-dt to the build Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 02/13] lua: built-in module datetime Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 03/13] test: datetime test Timur Safin via Tarantool-patches 2021-07-15 8:18 ` Timur Safin via Tarantool-patches [this message] 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 05/13] box: add messagepack support for datetime Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 06/13] lua: positive/negative cases in datetime test Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 07/13] lua: asctime and strfime fixed Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 08/13] box, lua: renamed t_datetime_tz structure to datetime_t Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 09/13] lua: calculated attributes for date Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 10/13] lua: tostring formatization in datetime.lua Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 11/13] test: allow relaxed date format without tz Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 12/13] lua: initial time duration support Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 13/13] lua: complete " Timur Safin via Tarantool-patches 2021-07-15 16:56 ` [Tarantool-patches] [RFC PATCH 00/13] Initial datetime support Oleg Babin via Tarantool-patches 2021-07-15 23:03 ` Timur Safin via Tarantool-patches 2021-07-16 6:58 ` Oleg Babin via Tarantool-patches 2021-07-22 10:01 ` Igor Munkin via Tarantool-patches 2021-07-22 12:54 ` Timur Safin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=fde3bf22f648bb5d1f3cd830d03dbb230da45944.1626335241.git.tsafin@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=tsafin@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [RFC PATCH 04/13] test: datetime string formatting' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox