Commit Diff


commit - e797a7483c0608c9c793f7388a2e446d2528768d
commit + ba140128df35d91f4de66435f4e72fa777fbb885
blob - /dev/null
blob + 4d5d46b35f17b66a7714ef52fdb19d9a5ff10e17 (mode 644)
--- /dev/null
+++ changelogs/unreleased/gh-7298-datetime-set-with-hour-nil.md
@@ -0,0 +1,4 @@
+## bugfix/datetime
+
+* Fixed a bug in datetime module when `date:set{hour=nil,min=XXX}`
+  did not retain original `hour` value. (gh-7298).
blob - 04e0bc7df5da907dbdb925011bbf4439538f7adb
blob + d4deadac7ff98fb75c9e28d8116f6159b8bc7107
--- src/lua/datetime.lua
+++ src/lua/datetime.lua
@@ -1023,7 +1023,7 @@ local function datetime_set(self, obj)
     end
 
     local lsecs = local_secs(self)
-    local h0 = math_floor(lsecs / (24 * 60)) % 24
+    local h0 = math_floor(lsecs / (60 * 60)) % 24
     local m0 = math_floor(lsecs / 60) % 60
     local sec0 = lsecs % 60
 
blob - 8f0edd53a0843c0b986940c72f8d78bde482bfb8
blob + a7089fc9e7915366168e103055debd1a2d0962ac
--- test/app-tap/datetime.test.lua
+++ test/app-tap/datetime.test.lua
@@ -1740,11 +1740,11 @@ test:test("Time :set{} operations", function(test)
             'day 9')
     test:is(tostring(ts:set{ hour = 6 }),  '2020-11-09T06:31:11+0300',
             'hour 6')
-    test:is(tostring(ts:set{ min = 12, sec = 23 }), '2020-11-09T04:12:23+0300',
+    test:is(tostring(ts:set{ min = 12, sec = 23 }), '2020-11-09T06:12:23+0300',
             'min 12, sec 23')
-    test:is(tostring(ts:set{ tzoffset = -8*60 }), '2020-11-09T04:12:23-0800',
+    test:is(tostring(ts:set{ tzoffset = -8*60 }), '2020-11-09T06:12:23-0800',
             'offset -0800' )
-    test:is(tostring(ts:set{ tzoffset = '+0800' }), '2020-11-09T04:12:23+0800',
+    test:is(tostring(ts:set{ tzoffset = '+0800' }), '2020-11-09T06:12:23+0800',
             'offset +0800' )
     -- timestamp 1630359071.125 is 2021-08-30T21:31:11.125Z
     test:is(tostring(ts:set{ timestamp = 1630359071.125 }),