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 D08066CAD4; Fri, 6 Aug 2021 16:00:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D08066CAD4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628254838; bh=WQndFOHx2VW+CMFIB17XdycRTugfb+bkTHShZIAhRpI=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=EBv6usqrNCb/SBD/M7Ji/F+BAuWIUtoqDo+lFpS1eCfe5OfSuiWsTmGxjBQGWYuKV sluYErD7AJMKT6YaKBLZMwKsY2MmOxU1hANH7MWyDhjUXxzg8aBRsUgDxEEjE04oho CyhuP22UIDTxFmj80+YFmi3MXrC8O8Q4pQTRauek= Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (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 0B3696CAD4 for ; Fri, 6 Aug 2021 16:00:37 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0B3696CAD4 Received: by smtp55.i.mail.ru with esmtpa (envelope-from ) id 1mBzSl-00028Q-Qd; Fri, 06 Aug 2021 16:00:36 +0300 To: Oleg Babin , Vladislav Shpilevoy References: <449cb4c7-c738-ed07-8517-61b663ad9f79@tarantool.org> <0931c9db-bd8e-0687-2c96-73fac1aeff7e@tarantool.org> <331a5d04-d756-fac0-fa07-cac594fa7ed8@tarantool.org> Message-ID: Date: Fri, 6 Aug 2021 16:00:35 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <331a5d04-d756-fac0-fa07-cac594fa7ed8@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F6525B29142351271182A05F538085040A886A2AC95C4BA20B6A83A060AB6C7A054820F8B885292B51EFEA42EF1B5F614 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7811C3E343B302E2EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F907CB39E8CA2E228638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D896D0DA237082E7734A3277163A750A5F117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE7B96B19DC4093321098B145E00970258D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE389DDFE3E282F3DD16136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006371F24DFF1B2961425731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A58C65DD2F4EB3DDF1EF4674B2D4B567BFFF44CF29E352590ED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3452F7993FB7281BFD3E77925A795C908694DAAE67D60D17468FF1CB660DBB6083BC3B3EA7C265F8A81D7E09C32AA3244C6ACB3CD172B7E0DC67F399C853C6BAECD9ADFF0C0BDB8D1F83B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojFhlvmGwdUwSaqFroR1zhEQ== X-Mailru-Sender: B5B6A6EBBD94DAD8AF988FF52E735F3BE45E264BD9B68F8EB5497A216822712C4B7B9B07E2CAC9C35C2808D6142752370A8ED71B308007E3DC85537438B7E1A423D748DE48713E689437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v3 2/9] lua: built-in module datetime 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: Safin Timur via Tarantool-patches Reply-To: Safin Timur Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On 06.08.2021 4:30, Oleg Babin wrote: > > On 06.08.2021 03:23, Safin Timur wrote: >> >> i.e. whenever we see not datetime or interva value datetime_cmp return >> nil, and all comparisons always return false. Please give me know if >> that's incorrect scenario and we should raise exception. This was the >> way Oleg Bain has requested it to behave. (return false for bogus data) >> > Hi! Seems you understood me wrong. It was only about equal comparison. > > ``` > > tarantool> uuid.new() == newproxy() > --- > - false > ... > > tarantool> uuid.new() > newproxy() > --- > - error: '[string "return require(''uuid'').new() > newproxy()"]:1: > incorrect value >     to convert to uuid as 1 argument' > ... > > ``` > > > However, currently I see that decimal have a bit different behaviour and > raises always: > > ``` > > tarantool> decimal.new(1) == newproxy() > --- > - error: '[string "return decimal.new(1) == newproxy()"]:1: expected > decimal, number >     or string as 2 argument' > ... > > tarantool> decimal.new(1) > newproxy() > --- > - error: '[string "return decimal.new(1) > newproxy()"]:1: expected > decimal, number >     or string as 1 argument' > ... > > ``` > > > IMO, the first case is better because we can check that two lua built-in > types > > are equal but can't compare them. > > ``` > > tarantool> {} == 'string' > --- > - false > ... > > tarantool> {} > 'string' > --- > - error: '[string "return {} > ''string''"]:1: attempt to compare string > with table' > ... > > ``` > > Now, that looks more or less consistent, will do it such! ``` tarantool> date = require 'datetime' --- ... tarantool> T = date('1970-01-01') --- ... tarantool> T == false --- - false ... tarantool> T == true --- - false ... tarantool> T < false --- - error: '[string "return T < false"]:1: incompatible types for comparison' ... tarantool> T <= 'string' --- - error: '[string "return T <= ''string''"]:1: incompatible types for comparison' ... ``` Patch is simple though ============================================================== diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua index 0bc86c9f3..509a2981f 100644 --- a/src/lua/datetime.lua +++ b/src/lua/datetime.lua @@ -245,12 +245,12 @@ end local function datetime_lt(lhs, rhs) local rc = datetime_cmp(lhs, rhs) - return rc ~= nil and rc < 0 or false + return rc ~= nil and rc < 0 or error('incompatible types for comparison', 2) end local function datetime_le(lhs, rhs) local rc = datetime_cmp(lhs, rhs) - return rc ~= nil and rc <= 0 or false + return rc ~= nil and rc <= 0 or error('incompatible types for comparison', 2) end local function datetime_serialize(self) ============================================================== Do we want to use that approach here? Thanks, Timur