Skip to content

Commit

Permalink
Added text_clock.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed May 12, 2013
1 parent 55734b5 commit 7d71f6c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions text_clock/text_clock.psgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Dancer;
use Time::Piece;

my $Display_Format = '';
my $Display_Week_Day = 1;
my $Display_Month = 1;
my $Display_Month_Day = 1;
my $Display_Year = 1;
my $Display_Time = 1;
my $Display_Time_Zone = 1;

get '/' => sub {
return date();
};


sub date {
if (! $Display_Format) {
$Display_Format = build_format();
}

return localtime->strftime($Display_Format);
}

sub build_format {
my @date_fmt;

push @date_fmt, '%A' if $Display_Week_Day;
push @date_fmt, '%B' if $Display_Month;
push @date_fmt, '%d' if $Display_Month_Day;
push @date_fmt, '%Y' if $Display_Year;
push @date_fmt, '%H:%M:%S' if $Display_Time;
push @date_fmt, '%Z' if $Display_Time_Zone;

return join ' ', @date_fmt;
}

dance;

0 comments on commit 7d71f6c

Please sign in to comment.