Created
February 9, 2018 12:19
-
-
Save evanre/a6d3a959be72621c3177efcd66199bf7 to your computer and use it in GitHub Desktop.
random date and time in nunjucks
This file contains 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 zeroCheck(num=0) -%} | |
{{- '0'+num if num < 9 else num -}} | |
{%- endmacro -%} | |
{%- macro checkDefault(num=0, rand=1) -%} | |
{{- num if num else range(1, rand) | random -}} | |
{%- endmacro -%} | |
{%- macro randTime(hour='', minute='') -%} | |
{{- zeroCheck(checkDefault(hour, 24)) -}}:{{- zeroCheck(checkDefault(minute, 59)) -}} | |
{%- endmacro -%} | |
{%- macro randDate(day='', month='', year='2018') -%} | |
{{- zeroCheck(checkDefault(day, 28)) }}-{{ zeroCheck(checkDefault(month, 12)) }}-{{ zeroCheck(checkDefault(year, 2019)) -}} | |
{%- endmacro -%} | |
<p>{{randDate()}} at {{randTime()}}</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sandbox for nunjucks is here