TrekBuddy - Outdoor companion
Bílý vrch
icon TrekBuddy
www.trekbuddy.net
Outdoor companion.
  • internal / bluetooth / simulator GPS
  • offline raster maps
  • smart GPX / raw NMEA logs
  • waypoints and simple navigation
  • custom views
  • MIDP and Symbian phones
  • Blackberry
  • Android
Visit wiki to see all features, guides and howtos. Project tracker.

Partners:    (Polish/Polski)(Polski) Compass mapy      (Polish/Polski)(Polski) Galileos mapy      (Polish/Polski)(Polski) CartoMedia      (Czech/Èesky)(Èesky) Eaglesoft trasy      (Polish/Polski)(Polski) ExpressMap     

 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
How to do TIME calculations?

 
Post new topic   Reply to topic    TrekBuddy Forum Index -> General discussion
View previous topic :: View next topic  
Author Message
JNT



Joined: 10 Jan 2009
Posts: 409
Location: Sweden

PostPosted: Thu Nov 06, 2014 11:07 am    Post subject: How to do TIME calculations? Reply with quote

It is easy to calculate how long something will take. I can easily get an answer as a number of hours (or minutes or seconds).
But how do I add it to the current time to get and display an "estimated time of completion"?

cms::time is in ms from 1/1/1970?
Is this in UTC?
How to take the time-zone into account?

Is there a simple way to do this?
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 409
Location: Sweden

PostPosted: Wed Jan 14, 2015 2:20 pm    Post subject: Reply with quote

Anybody?
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 409
Location: Sweden

PostPosted: Tue May 19, 2015 10:32 am    Post subject: Reply with quote

Nobody...?
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5658

PostPosted: Tue May 19, 2015 5:15 pm    Post subject: Reply with quote

Yes cms::time is UTC time, it is GPS time of last location info, in ms. I think it can be used as a number, ie. you can add/subtract etc.

For printing it as time I would I have to custom function (not a big issue). To check if time zone info is available on your platform please check Info->Technical->TimeZone Info format is "timezone;daylight-saving;offset in ms" (works on Symbian, Android and some non-smarts too).
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 409
Location: Sweden

PostPosted: Tue May 19, 2015 9:07 pm    Post subject: Reply with quote

I'm running Android and it says under the technical info:
"Europe/Stockholm; true; 3600000"

But now, how to use this in the CMS (and hecl)?

Formatting the number as time, I also requested here : http://www.trekbuddy.net/forum/viewtopic.php?t=7676

in the mean time I have managed to hack it in my hecl file, but the way I did it is quite cumbersome and the time zone is not automatic... so not very usable yet. I was hoping for an existing simple and elegant solution.
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5658

PostPosted: Tue May 19, 2015 10:34 pm    Post subject: Reply with quote

I was thinking one could do something like

print time cms::time
print time [+ cms::time cms::tzoffset]

First line would print UTC, second localtime. For your case, tzoffset would be 7200000 (3600000 hour for Stockholm, another hour for daylight). Not sure about "print" command syntax, this is just a thought. "tzoffset" is not available yet.

Would something like that work for you?
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 409
Location: Sweden

PostPosted: Wed May 20, 2015 7:25 am    Post subject: Reply with quote

kruch wrote:
I was thinking one could do something like

print time cms::time
print time [+ cms::time cms::tzoffset]

First line would print UTC, second localtime. For your case, tzoffset would be 7200000 (3600000 hour for Stockholm, another hour for daylight). Not sure about "print" command syntax, this is just a thought. "tzoffset" is not available yet.

Would something like that work for you?


Yes, that is sort-of what I've been doing (in my own awkward way):
Code:

# time zone nr of hrs difference from UTC
var sail::t-zone 1 

...

set sail::TetaTT [+ $sail::TTtimeTT [sail::spt $cms::time] [* 3600 $sail::t-zone]];  #UTC + 1hr  time zone
set sail::TetaTT-str [sail::timeformat $sail::TetaTT];

...

##### Calculates seconds past today #####
proc sail::spt {num-in} {
  return [* [- [/ [double $num-in] 86400000] [floor [/ [double $num-in] 86400000]]] 86400];
}

...

##### Formats number into time hh:mm:ss #####
proc sail::timeformat {time-in} {
  if {< $time-in 0} {
    set time-out "-";
    set time-in [- 0 $time-in];
  } else {
    set time-out "";
    }
    set sail::hrs [round [floor [/ $time-in 3600]]];
    set sail::min [round [floor [/ [- $time-in [* $sail::hrs 3600]] 60]]];
    set sail::sec [round [floor [- $time-in [+ [* $sail::hrs 3600] [* $sail::min 60]]]]];

    if {> $sail::hrs 23} {
      set sail::n-days [round [floor [/ $sail::hrs 24]]];
      append $time-out "+";
      append $time-out $sail::n-days;
      append $time-out "d ";
      set sail::hrs [- $sail::hrs [* $sail::n-days 24]];
    }
    if {< $sail::hrs 10} {
      append $time-out "0";
    }
    append $time-out $sail::hrs;
    append $time-out ":";
    if {< $sail::min 10} {
      append $time-out "0";
    }
    append $time-out $sail::min;
    append $time-out ":";
    if {< $sail::sec 10} {
      append $time-out "0";
    }
    append $time-out $sail::sec;
    return $time-out;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    TrekBuddy Forum Index -> General discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group