Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add an alarm clock example for sleep-till
  • Loading branch information
Paul Cochrane committed Sep 4, 2015
1 parent cbb84c8 commit d20da36
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Type/Temporal.pod
Expand Up @@ -80,6 +80,30 @@ appropriate point in time, and cast to an C<Instant>.
minute => 5);
say sleep-till $instant.Instant # => True (eventually...)
This could be be used as a primitive kind of alarm clock. For instance, say
you need to get up at 7am on the 4th of September 2015, but for some reason
your usual alarm clock is broken and you only have your laptop. You can
specify the time to get up (being careful about timezones, since
C<DateTime.new> uses UTC by default) as an C<Instant> and pass this to
C<sleep-till>, after which you can play an mp3 file to wake you up instead
of your normal alarm clock. This scenario looks roughly like this:
# DateTime.new uses UTC by default, so get timezone from current time
my $timezone = DateTime.now.timezone;
my $instant = DateTime.new(
year => 2015,
month => 9,
day => 4,
hour => 7,
minute => 0,
timezone => $timezone
).Instant;
sleep-till $instant;
qqx{mplayer wake-me-up.mp3};
This code, if necessary, can run as a one-liner so you can e.g. get up in
time for the talks at YAPC.
=end pod

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit d20da36

Please sign in to comment.