User:Stux/sandbox2

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
(Manual time approach)
(turns out there is a modulo operator after all! :D)
Line 19: Line 19:
<pre>
<pre>
-
{{#expr: 121%60}} <br/><!-- confirm there is no modulo -->
 
-
{{#expr: 121 mod 60}} <br/><!-- confirm there is no modulo -->
 
-
 
-
 
{{#expr: 121/60}} <br/><!-- convert 121 seconds to minutes -->
{{#expr: 121/60}} <br/><!-- convert 121 seconds to minutes -->
{{#expr: 119/60}} <br/><!-- convert 119 seconds to minutes -->
{{#expr: 119/60}} <br/><!-- convert 119 seconds to minutes -->
Line 28: Line 24:
{{#expr: 119/60 round 0}} <br/><!-- round 119 seconds to minutes -->
{{#expr: 119/60 round 0}} <br/><!-- round 119 seconds to minutes -->
</pre>
</pre>
-
 
-
{{#expr: 121%60}} <br/><!-- confirm there is no modulo -->
 
-
{{#expr: 121 mod 60}} <br/><!-- confirm there is no modulo -->
 
-
 
{{#expr: 121/60}} <br/><!-- convert 121 seconds to minutes -->
{{#expr: 121/60}} <br/><!-- convert 121 seconds to minutes -->
Line 39: Line 31:
* Fortunately, we should be able to use the above logic for IF statements. ''Unfortunately'', this crazy logic may time out...
* 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:
 +
<pre>
 +
{{#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 -->
 +
</pre>
 +
 +
{{#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 -->
 +
 +
* So we can now easily convert seconds to hh:mm:ss:
 +
<pre>
 +
{{#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 -->
 +
</pre>
 +
{{#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 -->
 +
* Okay, so this doesn't do zero padding :-/
----
----

Revision as of 22:11, 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 :-/


Personal tools