TUTORIAL: Creating a clock that displays in 12 hour time format

Under Consideration eggroll ago

Replies (4)

FYI, I'm not insane. The gaping spaces of blank lines were not my doing. :>|

For those looking for additional insight into JIM string indexing when it comes to the System Time (aka System Hour) constant, here is my theory, as promised at the end of Step 10 of the tutorial.

The substring indexing of System Time isn't particularly intuitive. Since the indexing of strings is zero based (first index is 0, second index is 1, etc.), the hour should be contained and confined to the first two positions. Therefore, with a system time of say "16:32:54", one would think the substring expression to capture the hours as a number would be "Substring(System Hour, 0, 1)" returning the number "16". Likewise, capturing minutes as a number would be achieved, one would also think, with "Substring(System Hour, 3, 4)", skipping from the "1" index in hours to the "3" index in minutes, presumably jumping the "2" index, which should belong to the colon ":" that separates hours from minutes.

In actuality, the way I believe string indexing of the "System Hour" constant in JIM works is that in order to capture both digits of the hour as a number, you need to index the substring as 0-3, even though this would seem to capture the colon along with the two hour digits. What it actually appears to capture is the two hour digits and perhaps some sort of system character that says "a colon goes after this number in this context", rather than it being a simple colon ":" text character. The same holds true for minutes, with the indexes for capturing both digits of minutes being 3-5. "Substring(System Hour, 0, 2)" returns "16", not "16:", and "Substring(System Hour, 3, 5)" returns "32", not "32:".

I assume this implementation has to do with preserving the numerical value of the hour so that mathematical operations can be performed on it rather than it being solely text, even though you are using a text operator "Substring" to capture that number. It seems that within JIM, numerical characters have a dual identity as both numbers and text and this implementation preserves them for use as both.

The frequent use of words like "seems", "appears", etc. within this post should indicate that this is merely a guess. But knowing, it least, that it functions this way may save you some time as you create event expressions in your prototypes or least more clearly understand the substring indexing in the tutorial.

Hope it helps. Would love to hear a better explanation.

Cheers!

Dear Eggroll,

Thank you so much for taking the time to write and share this tutorial with the community. It's awesome! We have reviewed it and it is a great way to accomplish that. If you agree, we would like to convert and add it as a tutorial into our Support section: https://www.justinmind.com/support.

Regarding your last question, take into account that the start and end range values that we have introduced into the substring (text function) works the same way as Javascript (the language we use for the simulation part). We have applied the standard:

Best,

Sonia Durán

Hi Sonia,

Yes, please feel free to convert and add it to the support section. I'm glad that others might find it useful.

Also, apparently it has been awhile since I've had to use substring within javascript because I had no recollection that the end index was exclusive. That is a much simpler explanation and certainly makes my secret system "a colon goes after this" conspiracy character sound crazy. After you've posted the tutorial in the support section, I wouldn't at all be opposed to you deleting this post. :-)

Cheers!!

Dear Eggroll,

The task of creating the tutorial has been added to the backlog. As soon as it has been published I'll let you know.

Best,

Sonia Durán

Great, thanks!

I just noticed there is a small error in the tutorial. In Step 8, the line "select the text box (in this example named "clock") as the element to set the value of" is incorrect. It should read "time_text" instead of "clock".

Dear Eggroll,

Thank you for your contribution. We'll take this note into account. :)

Best,

Sonia Durán