Charmed Quark Systems, Ltd. - Support Forums and Community

Full Version: Displaying countdown timer in clock format (not hex)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dean answered this question via email. I thought I would post the Q&A for future searchers.
=====================
Question
=====================
Hi Dean,

I’ve searched the forum and found scary stuff like this:
http://www.charmedquark.com/vb_forum/arc...-6500.html

I have a timer driver with moniker ├ó┬Ç┬£Timer├ó┬Ç┬Ø

I have a countdown timer cdtimer 1 that I set to 3 minutes or 20 minutes depending on which button is pushed. E.g.,
Devices::FieldWrite
P1=Timers.InvokeCmd
P2=ResetCD 1 Minutes 3
P3=True

Here is what I would like to do:

I want to display the time remaining in hh:mmConfuseds and see it count down in an interface. The timer value will never exceed 24 hours. I want to see the seconds tick by.

==================
Dean's Answer
==================

Actually, it’s really easy to do now. What you saw there in that thread was long ago. A lot of stuff has been added since then to help with that sort of stuff.

These days you can use a Time Text widget, a field based one in this case. It has a formatting scheme where you can just tell it what components of the associated time field’s value to display. You just set up a string with replacement tokens. The text displayed will be built up by replacing those tokens with the values of the time that they represent. The tokens are defined in the Time class:

http://www.charmedquark.com/Web2/ExtCont...untime.htm

But what you want is a standard format, and there’s a single token that does that all in one shot, %(z):
'z' - Calculates the elapsed hours, minutes and seconds, and formats them out in two digit, leading zero form with local specific separators, e.g. 03:15:08.
So just create a field based Time Text widget, pop up the widget’s configuration, select the countdown timer field you want to display, and then on the tab where you set the format, just enter %(z) as the pattern. That should get you want you want. To make it ‘clock-like’ just set the font to a non-proportional font, so that each digit takes up the same width. That way it won’t move around as the digits change.

If you would like it not to display leading hour zeros, use capital Z, e.g. %(Z). That will display the hours if non-zero, but leave them out if zero. Though it does also mean that, when it hits an hour and moves below it, it’ll suddenly drop the hours and just show the minutes/seconds, whereas %(z) will display the hours always, even if zero but it’s consistently going to be 8 characters. So whichever you find works visually the best for you.

----------------------------------------------------
Dean Roddey
BTW, if you need to do something like this at the action level, the System::FormatTimeVal() command (I think that's the right name) does basically the same sort of time value formatting to text. It supports that same pattern based scheme.
Joe just pointedout that the %(X) and %(Z) tokens aren't doing what they should. They are never days or hours (respectively), but they should be if the days or hours are non-zero. I fixed this for the next drop.