In 5552 I added a lua function set_clock to set the camera date / time.
syntax is
set_clock(year, month, day, hour, minute, second)
Values are integers and all are required.
Values are all exactly as they would appear in the camera clock: 4 digit year, month and day numbers start at 1. It is not aware of DST, the displayed time after setting is the values set, regardless of the DST setting.
If you want to set just one value, for example to set one hour forward, you could do something like
t=os.date('*t') -- current date / time as table
set_clock(t.year,t.month,t.day,t.hour + 1, t.min, t.sec)
If you want to set it from a timestamp value, you can pass the timestamp as the second parameter of os.date and use it as above. For example, to set 10 seconds ahead, you could do
t=os.date('*t', os.time() + 10)
set_clock(t.year,t.month,t.day,t.hour, t.min, t.sec)
This is a safer than manipulating individual values, since you don't have to worry about days / hours etc going out of range.
It uses the SetDate eventproc. Advantage of having it built in is that it avoids the need to call registration event procs which can have negative side effects. Additionally, it takes care of updating tick_count_offset for DNG subsec time.
The CHDK code doesn't do any validation, so if you decide to set it to 25:99 hours on Feb 30, you get whatever the camera OS does this that.
I called it set_clock because it's not symmetric with any of the various get date/time functions.
From my testing, it updates the RTC, so the set time will be kept even if the camera shuts down abnormally after the set (discussion in
https://chdk.setepontos.com/index.php?topic=13856.msg143971#msg143971)
edit:
Corrected code examples to use set_clock(). Thanks Mlapse for catching the typo.
edit:
In 5553, I fixed a bug that caused seconds to be set to the minute value
