Skip to content

Instantly share code, notes, and snippets.

@bessarabov
Created May 1, 2015 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bessarabov/692476d1c7de5f5f09ec to your computer and use it in GitHub Desktop.
Save bessarabov/692476d1c7de5f5f09ec to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use feature 'say';
use Moment;
my @weekdays = qw(
monday
tuesday
wednesday
thursday
friday
saturday
sunday
);
foreach my $weekday (@weekdays) {
while (1) {
my $current_timestamp = Moment->now()->get_timestamp();
my $random_timestamp = int(rand($current_timestamp));
my $random_moment = Moment->new( timestamp => $random_timestamp);
if ($random_moment->get_weekday_name() eq $weekday) {
say $random_moment->get_dt()
. " "
. $random_moment->get_weekday_name()
;
last;
};
}
}
__END__
output:
1990-10-22 03:12:17 monday
2010-11-02 04:26:12 tuesday
2000-12-06 21:25:42 wednesday
2011-11-10 20:19:28 thursday
1992-01-10 20:10:25 friday
1995-01-07 17:48:43 saturday
1995-11-19 18:59:37 sunday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment