Last active
December 22, 2015 22:49
-
-
Save SimonRichardson/6542362 to your computer and use it in GitHub Desktop.
Macro time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro $time { | |
| case {_ + $x:lit h $rest ... } => { | |
| return #{ .map(function(x) { return x + ($x * 1000 * 60 * 60) }) $time $rest ... } | |
| } | |
| case {_ + $x:lit m $rest ... } => { | |
| return #{ .map(function(x) { return x + ($x * 1000 * 60) }) $time $rest ... } | |
| } | |
| case {_ + $x:lit s $rest ... } => { | |
| return #{ .map(function(x) { return x + ($x * 1000) }) $time $rest ... } | |
| } | |
| case {_ + $x:lit ms $rest ... } => { | |
| return #{ .map(function(x) { return x + $x }) $time $rest ... } | |
| } | |
| case {_ $x:lit h $rest ... } => { | |
| return #{ _.Hours($x * 1000 * 60 * 60) $time $rest ... } | |
| } | |
| case {_ $x:lit m $rest ... } => { | |
| return #{ _.Minutes($x * 1000 * 60) $time $rest ... } | |
| } | |
| case {_ $x:lit s $rest ... } => { | |
| return #{ _.Seconds($x * 1000) $time $rest ... } | |
| } | |
| case {_ $x:lit ms $rest ... } => { | |
| return #{ _.Milliseconds($x) $time $rest ... } | |
| } | |
| case {_ } => { | |
| return #{} | |
| } | |
| } | |
| var a = $time 1 h + 2 m + 3 s + 4 ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment