Posts: 12
Threads: 3
Joined: Oct 2022
Reputation:
0
Hello,
I want to cut part of a value :
-- value1 --> 11:36:23, Samedi
I want to recover the first part - hour without the day
-- 11:36:23
Thanks.
Posts: 306
Threads: 59
Joined: Dec 2019
Reputation:
13
(08.10.2022, 09:38)Chris Wrote: Hello,
I want to cut part of a value :
-- value1 --> 11:36:23, Samedi
I want to recover the first part - hour without the day
-- 11:36:23
Thanks. Hi,
this could work
local value1 = '11:36:23, Samedi'
local data = '%d%d:%d%d:%d%d'
local res = string.match(value1, data)
log(res)
Posts: 12
Threads: 3
Joined: Oct 2022
Reputation:
0
09.10.2022, 11:03
(This post was last modified: 09.10.2022, 11:22 by Chris.)
Hello,
Thanks for your answer, but it doesn't work --> value: 0:00:00
https://zupimages.net/viewer.php?id=22/40/8bpk.png
value1 = grp.getvalue("32/1/20")
value2 = grp.getvalue("32/1/21")
local data = '%d%d:%d%d:%d%d'
local res = string.match(value2, data)
grp.write('32/1/30', res)
grp.write('32/1/28', value1)
log(res)
Posts: 167
Threads: 20
Joined: Apr 2017
Reputation:
2
Hi Chris, waht kind of datatype is your "32/1/21" ?
and what result do you get if you do
Code: value2 = grp.getvalue("32/1/21")
log(value2)
Posts: 306
Threads: 59
Joined: Dec 2019
Reputation:
13
(09.10.2022, 11:03)Chris Wrote: Hello,
Thanks for your answer, but it doesn't work --> value: 0:00:00
https://zupimages.net/viewer.php?id=22/40/8bpk.png
value1 = grp.getvalue("32/1/20")
value2 = grp.getvalue("32/1/21")
local data = '%d%d:%d%d:%d%d'
local res = string.match(value2, data)
grp.write('32/1/30', res)
grp.write('32/1/28', value1)
log(res)
Script works if you pass a string, if you pass a table it can't work
Best regard
Posts: 12
Threads: 3
Joined: Oct 2022
Reputation:
0
Hi Dré,
DP : 10. 3 octets heure / jour
User script:6: bad argument #1 to 'match' (string expected, got table)
stack traceback:
[C]: in function 'match'
User script:6: in main chunk
Posts: 306
Threads: 59
Joined: Dec 2019
Reputation:
13
(09.10.2022, 14:06)Chris Wrote: Hi Dré,
DP : 10. 3 octets heure / jour
User script:6: bad argument #1 to 'match' (string expected, got table)
stack traceback:
[C]: in function 'match'
User script:6: in main chunk
Try to change in this this way
local res = string.match(tostring(value2[1], data)
Best regards
Posts: 167
Threads: 20
Joined: Apr 2017
Reputation:
2
09.10.2022, 14:39
(This post was last modified: 09.10.2022, 14:44 by Dré.)
try this
Code: value1 = grp.getvalue('32/1/20')
-- time table
time = {
day = wday,
hour = value1.hour,
minute = value1.min,
second = value1.sec,
}
-- date table
date = {
day = value1.day,
month = value1.month,
year = value1.year,
}
value1 = string.format("%02d", value1.hour) .. ":" .. string.format("%02d", value1.min) .. ":" .. string.format("%02d", value1.sec)
log(value1)
grp.write('32/1/30', value1)
log(value1)
I also see there was use " insteed of '
value1 = grp.getvalue( "32/1/20 ")
Posts: 12
Threads: 3
Joined: Oct 2022
Reputation:
0
Dré your solution works, thank you!
CristianAgata, thank you, I'll try your method soon,
good evening !
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Next firmware will have an option to hide day and/or seconds for data type 10 (3 byte time / day).
Dré's script is correct. string.format supports multiple arguments so the script can be shorter. There's no different in using single or double quotes in Lua.
Code: value = event.getvalue()
time = string.format('%d:%02d:%02d', value.hour, value.min, value.sec)
log(time)
|