NetTalk Central

Author Topic: Times over midday and midnight  (Read 3383 times)

John Fligg

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
    • Ambrit Software
    • Email
Times over midday and midnight
« on: February 26, 2012, 01:16:47 PM »
I have a start time and end time plus a duration field.

I add the duration to the start field to derive the end time. However because the time is displayed as AM and PM, if the time is 11AM and I add 2 hours I only get 12AM and not 1PM.

Obviously it cannot calculate over the midday/midnight barrier.

What is the best way to perform the calulcation so that durations takes this barrier into account?

Thanks

John

AZIS350

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
Re: Times over midday and midnight
« Reply #1 on: February 26, 2012, 04:51:54 PM »
If you use the standard clarion time fields, the time is calculated in 100th of a second and automatically calculates the time of day. Just use a time picture token (i.e. @t3) and it will display the am/pm for you based upon the correct time. So if the clarion time field is represents what would be 11AM (which would be I believe around 3,960,000 internally), and you add 2 hours (2 hrs * 60 min/hr * 60 sec/min * 100 = 720,000) then the time field internally is 4,680,000. Using your T3 token that would now show 1PM. All you need to do is when the duration is entered by the user (i.e. 2 hours), multiple it by the above formula and add it to your start time and the result is your end time. We use this formula all the time in all of our clarion and NT web apps.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Times over midday and midnight
« Reply #2 on: February 26, 2012, 11:31:00 PM »
>> and I add 2 hours I only get 12AM and not 1PM.

there was a bug displaying times between 12 and 1, but that's been fixed so update to the latest build.

>> Obviously it cannot calculate over the midday/midnight barrier.

wrong. It'll go over midday just fine.

Obviously for going over midnight you should "mod" the sum by 24 hours. ie
endtime = ((starttime + duration) % 8640000) + 1

For formatting reasons (clarion measures time _elapsed_) adding an extra 1 is usually a good idea.

cheers
Bruce

John Fligg

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
    • Ambrit Software
    • Email
Re: Times over midday and midnight
« Reply #3 on: February 27, 2012, 12:35:50 AM »
Bruce v6.21 (17 Feb) is latest on website??

Also the main page says 6.21 is the latest build and that is what I am now.

Thanks

John

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Times over midday and midnight
« Reply #4 on: February 27, 2012, 02:25:14 AM »
you will need to make a small example then showing the effect.