From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 4C0E16EC55; Thu, 15 Jul 2021 11:20:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4C0E16EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626337254; bh=a/ZAqp+0UKdvLzndJOU78WYcBxMQ4DeMRd8/kQMxcwU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ZwYjKwtgIih4AgtsLsjXBSqUwGH3E037L+72C2gIQc0qVmmxuR+cdEQCEGi4OP4VP TjFCqT/DieIR7Te0S1xWmLRYP5fjT6XI8+ei54V8nz54hJGHMU7btHkRopshH5X1lX 1968aM7jB5n0ptaMEjs/wfy7C1+q0f0Ui0BK6taY= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 534386EC5A for ; Thu, 15 Jul 2021 11:18:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 534386EC5A Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1m3wa4-00070N-D2; Thu, 15 Jul 2021 11:18:52 +0300 To: v.shpilevoy@tarantool.org Date: Thu, 15 Jul 2021 11:18:10 +0300 Message-Id: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30288BCF456A452ECBCD3030350682103182A05F538085040B2D14BB8C39487A84BECABE837D5247BCE711CB56BB34CF21A225A5103AAED25 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE716FAD50E497B9C14EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063764345650F0BBEB0B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D852A1A02C83B6EBD2316EC11070450C39117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEC24E1E72F37C03A0C5236E9430F51F07D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3735DFC8FA7AC120703F1AB874ED89028C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637AD0424077D726551EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CE68746B1F2AB10C6AFA06E0A1C33A9E98B09B8EE2416D43C9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF3033054805BDE987699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346F8291983715AC66B4AC804BFEE43E81D1CD84855B880166CBD0132855D249939DD35D2D6D8EDB191D7E09C32AA3244C861A46FF365F412CEA15B12D2242BA0B97FE24653F78E66883B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjnYxxC9kpVb5rZXZs5rI6/ X-Mailru-Sender: B5B6A6EBBD94DAD8DA84A184D75F19DB2E7B7B20C3E75D0F5A69C4D9E2FF6A6564CA3E16C239DCF91EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [RFC PATCH 04/13] test: datetime string formatting X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Timur Safin via Tarantool-patches Reply-To: Timur Safin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" * 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