Created
November 20, 2013 19:20
-
-
Save bessarabov/7569293 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use strict; | |
use warnings FATAL => 'all'; | |
use utf8; | |
use open qw(:std :utf8); | |
use Class::Date qw(date); | |
use Perl6::Form; | |
sub get_date_from_timestamp { | |
my ($timestamp) = @_; | |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($timestamp); | |
my @days = qw(воскресенье понедельник вторник среда четверг пятница суббота); | |
my $date = | |
$days[$wday] | |
. ", " | |
. sprintf("%02d", $hour) | |
. ":" | |
. sprintf("%02d", $min) | |
; | |
return $date; | |
} | |
sub main { | |
my @dates = ( | |
'2001-09-09 00:03', | |
'2001-09-09 05:39', | |
'2001-09-09 05:46', | |
# the problem is between these 2 dates =) | |
'2001-09-09 05:47', | |
'2001-09-09 05:56', | |
'2001-09-09 10:43', | |
); | |
my @timestamps = map { date($_)->epoch() } @dates; | |
# from `perldoc -f sort`: | |
# | |
# If SUBNAME or BLOCK is omitted, "sort"s in standard string comparison | |
# order. | |
# | |
# So, it is the same as saying: `sort {$a cmp $b} @timestamps` | |
# And the solution is to use `sort {$a <=> $b} @timestamps` =) | |
foreach my $timestamp (sort @timestamps) { | |
print form "{<<<<<<<<<<<<<<<<<<<<} - {>>>>>>>>>>>} ", | |
get_date_from_timestamp($timestamp), | |
$timestamp, | |
; | |
} | |
} | |
main(); | |
__END__ | |
script output: | |
воскресенье, 05:47 - 1000000020 | |
воскресенье, 05:56 - 1000000560 | |
воскресенье, 10:43 - 1000017780 | |
воскресенье, 00:03 - 999979380 | |
воскресенье, 05:39 - 999999540 | |
воскресенье, 05:46 - 999999960 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment