Wikia

CHDK Wiki

Changes: Camera timestamps

Edit

Back to page

(Created page with "''...some notes on how the cameras handles dates/times - by reyalP, taken from [http://chdk.setepontos.com/index.php?topic=7560.msg80635#msg80635 this] forum post.'' *The follo...")
 
(fix DST error in offset calculation)
 
(One intermediate revision by one user not shown)
Line 5: Line 5:
   
   
The timestamp returned by camera os.time is like a unix timestamp, except it always treats the current camera time as UTC:
+
The timestamp returned by camera os.time is like a [http://en.wikipedia.org/wiki/Unix_time Unix timestamp], except it always treats the current camera time as UTC:
 
=return os.date('%c',0)
 
=return os.date('%c',0)
 
1:return:'Thu Jan 1 00:00:00 1970'
 
1:return:'Thu Jan 1 00:00:00 1970'
Line 26: Line 26:
   
 
Assuming your camera and PC are set to the same local time, you just need the offset of PC local time from UTC in seconds to add or subtract. In PC side lua this can be obtained with
 
Assuming your camera and PC are set to the same local time, you just need the offset of PC local time from UTC in seconds to add or subtract. In PC side lua this can be obtained with
local tslocal=os.time()
+
local tslocal=os.time()
return tslocal - os.time(os.date('!*t',tslocal))
+
local ttmp = os.date('!*t',tslocal)
+
ttmp.isdst = os.date('*t',tslocal).isdst
  +
return tslocal - os.time(ttmp)
 
*If your camera time changes (due to using travel time zone, DST option, or setting the clock) there's really no way to recover the absolute time unless you kept track externally.
 
*If your camera time changes (due to using travel time zone, DST option, or setting the clock) there's really no way to recover the absolute time unless you kept track externally.
   
Line 47: Line 47:
   
 
''(! in lua os.date means display UTC... this doesn't work on the camera, of course)''
 
''(! in lua os.date means display UTC... this doesn't work on the camera, of course)''
 
 
[[Category:Scripts]]
 
[[Category:Scripts]]
 
[[Category:CHDK internals]]
 
[[Category:CHDK internals]]

Latest revision as of 02:54, September 14, 2013

...some notes on how the cameras handles dates/times - by reyalP, taken from this forum post.


  • The following applies to both vxworks (a540) and dryos R31 (d10), except that a540 doesn't have DST or alternate timezone functions. Would be interesting to know if GPS enabled cams behave differently, since they do have an absolute time reference.


The timestamp returned by camera os.time is like a Unix timestamp, except it always treats the current camera time as UTC:

=return os.date('%c',0)
1:return:'Thu Jan  1 00:00:00 1970'


Switching to the alternate timezone on the camera UI changes the underlying timestamp (also timestamps recorded on the file, seen by stat):

Home timezone (PST):

con 4> =return os.date(),os.time()
5:return:'Sat Jan 28 16:01:58 2012'
5:return:1327766518

Alternate timezone (IST, yes, it really is :30 off):

con 5> =return os.date(),os.time()
6:return:'Sun Jan 29 05:32:49 2012'
6:return:1327815169
  • Exif values appear to be a straight strftime on the camera.


Assuming your camera and PC are set to the same local time, you just need the offset of PC local time from UTC in seconds to add or subtract. In PC side lua this can be obtained with

   local tslocal=os.time()
   local ttmp = os.date('!*t',tslocal)
   ttmp.isdst  = os.date('*t',tslocal).isdst
   return tslocal - os.time(ttmp)
  • If your camera time changes (due to using travel time zone, DST option, or setting the clock) there's really no way to recover the absolute time unless you kept track externally.


You can display a camera time in local PC time by pretending PC current timezone is UTC:

camera time:

=return os.date('%c',1327766494)
1:return:'Sat Jan 28 16:01:34 2012'

PC, wrong:

!return os.date("%c",1327766494)
="01/28/12 08:01:34"

PC, OK

!return os.date("!%c",1327766494)
="01/28/12 16:01:34"

(! in lua os.date means display UTC... this doesn't work on the camera, of course)

Around Wikia's network

Random Wiki