lang: funcs: Add a weekday function to the datetime package

This returns the day of the week. It also includes a helpful example
demonstrating how this functionality can be fun!
This commit is contained in:
James Shubin
2019-05-06 06:24:07 -04:00
parent 43839d1090
commit fc6032d3b7
2 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import "datetime"
import "fmt"
$now = datetime.now()
$day = datetime.weekday($now)
$is_friday = $day == "friday"
$s1 = template("Hello! It is now: {{ datetime_print . }}\n", $now)
$s2 = if $is_friday {
"It's friday!!! (don't break anything, read-only)"
} else {
if $day == "saturday" || $day == "sunday" {
"It's the weekend!"
} else {
fmt.printf("Unfortunately, it is %s. Go to work!", $day)
}
}
print "msg" {
msg => $s1 + $s2,
}
file "/tmp/files/" {
state => "exists",
mode => if $is_friday { # this updates the mode, the instant it changes!
"0550"
} else {
"0770"
},
}