Skip to content

Instantly share code, notes, and snippets.

@SimonRichardson
Last active December 22, 2015 22:49
Show Gist options
  • Select an option

  • Save SimonRichardson/6542362 to your computer and use it in GitHub Desktop.

Select an option

Save SimonRichardson/6542362 to your computer and use it in GitHub Desktop.
Macro time
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