User:Stux/sandbox2
From Homestar Runner Wiki
(Difference between revisions)
(turns out there is a modulo operator after all! :D) |
(add full hh:mm:ss calculations) |
||
| Line 43: | Line 43: | ||
{{#expr: 119 mod 60}} <br/><!-- confirm there is a modulo operator --> | {{#expr: 119 mod 60}} <br/><!-- confirm there is a modulo operator --> | ||
| - | * So we can now easily convert seconds to hh:mm:ss: | + | * So we can now "easily" convert seconds to hh:mm:ss: |
<pre> | <pre> | ||
{{#expr: (121-(121 mod 60))/60}}:{{#expr:121 mod 60}} <br/> <!-- 121 seconds to mm:ss --> | {{#expr: (121-(121 mod 60))/60}}:{{#expr:121 mod 60}} <br/> <!-- 121 seconds to mm:ss --> | ||
| Line 51: | Line 51: | ||
{{#expr: (119-(119 mod 60))/60}}:{{#expr:119 mod 60}} <br/> <!-- 119 seconds to mm:ss --> | {{#expr: (119-(119 mod 60))/60}}:{{#expr:119 mod 60}} <br/> <!-- 119 seconds to mm:ss --> | ||
* Okay, so this doesn't do zero padding :-/ | * Okay, so this doesn't do zero padding :-/ | ||
| + | |||
| + | |||
| + | * For now let's do more complicated examples: | ||
| + | <pre> | ||
| + | {{#ifexpr: (3601>=3600)|{{#expr: (3601-(3601 mod 3600))/3600}}:|}}{{#expr: (3601-(3601 mod 60))/60}}:{{#expr:3601 mod 60}} <br/> <!-- 3601 seconds to hh:mm:ss --> | ||
| + | {{#ifexpr: (3599>=3600)|{{#expr: (3599-(3599 mod 3600))/3600}}:|}}{{#expr: (3599-(3599 mod 60))/60}}:{{#expr:3599 mod 60}} <br/> <!-- 3599 seconds to hh:mm:ss --> | ||
| + | {{#ifexpr: (7199>=3600)|{{#expr: (7199-(7199 mod 3600))/3600}}:|}}{{#expr: (7199-(7199 mod 60))/60}}:{{#expr:7199 mod 60}} <br/> <!-- 7199 seconds to hh:mm:ss --> | ||
| + | </pre> | ||
| + | {{#ifexpr: (3601>=3600)|{{#expr: (3601-(3601 mod 3600))/3600}}:|}}{{#expr: (3601-(3601 mod 60))/60}}:{{#expr:3601 mod 60}} <br/> <!-- 3601 seconds to hh:mm:ss --> | ||
| + | {{#ifexpr: (3599>=3600)|{{#expr: (3599-(3599 mod 3600))/3600}}:|}}{{#expr: (3599-(3599 mod 60))/60}}:{{#expr:3599 mod 60}} <br/> <!-- 3599 seconds to hh:mm:ss | ||
| + | {{#ifexpr: (7199>=3600)|{{#expr: (7199-(7199 mod 3600))/3600}}:|}}{{#expr: (7199-(7199 mod 60))/60}}:{{#expr:7199 mod 60}} <br/> <!-- 7199 seconds to hh:mm:ss --> | ||
---- | ---- | ||
Revision as of 22:29, 1 January 2025
Testing time:
{{#time: z | 20071031}}
Yields: 303
- 121 seconds?
{{#time: i:s | 121}}
Yields: Error: invalid time
- So time doesn't support converting seconds to "hh:mm:ss" format, unfortunately. We gotta do it manually using Help:ParserFunctions##expr:, but now we have two more problems:
- There is no modulo operation, and we can't use "round" to easily emulate it.
- So, here goes nothing:
{{#expr: 121/60}} <br/><!-- convert 121 seconds to minutes -->
{{#expr: 119/60}} <br/><!-- convert 119 seconds to minutes -->
{{#expr: 121/60 round 0}} <br/><!-- round 121 seconds to minutes -->
{{#expr: 119/60 round 0}} <br/><!-- round 119 seconds to minutes -->
2.0166666666667
1.9833333333333
2
2
- Fortunately, we should be able to use the above logic for IF statements. Unfortunately, this crazy logic may time out...
- But wait! Turns out there is module after all:
{{#expr: 121%60}} <br/><!-- confirm there is no modulo symbol -->
{{#expr: 121 mod 60}} <br/><!-- confirm there is a modulo operator -->
{{#expr: 119 mod 60}} <br/><!-- confirm there is a modulo operator -->
Expression error: Unrecognised punctuation character "%"
1
59
- So we can now "easily" convert seconds to hh:mm:ss:
{{#expr: (121-(121 mod 60))/60}}:{{#expr:121 mod 60}} <br/> <!-- 121 seconds to mm:ss -->
{{#expr: (119-(119 mod 60))/60}}:{{#expr:119 mod 60}} <br/> <!-- 119 seconds to mm:ss -->
2:1
1:59
- Okay, so this doesn't do zero padding :-/
- For now let's do more complicated examples:
{{#ifexpr: (3601>=3600)|{{#expr: (3601-(3601 mod 3600))/3600}}:|}}{{#expr: (3601-(3601 mod 60))/60}}:{{#expr:3601 mod 60}} <br/> <!-- 3601 seconds to hh:mm:ss -->
{{#ifexpr: (3599>=3600)|{{#expr: (3599-(3599 mod 3600))/3600}}:|}}{{#expr: (3599-(3599 mod 60))/60}}:{{#expr:3599 mod 60}} <br/> <!-- 3599 seconds to hh:mm:ss -->
{{#ifexpr: (7199>=3600)|{{#expr: (7199-(7199 mod 3600))/3600}}:|}}{{#expr: (7199-(7199 mod 60))/60}}:{{#expr:7199 mod 60}} <br/> <!-- 7199 seconds to hh:mm:ss -->
1:60:1
59:59
