summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-02-26 10:43:59 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-02-26 10:43:59 +0100
commit0c140f0c79d62a426838097cf3fc09da2f3f89a3 (patch)
treeb2d7f3a277292acdfb67285c6ec9e4d9c4686fa3 /lib
parentbd7537b677d46f70a2446fcc00d9834d19a68b6b (diff)
Slightly improve date handling
Diffstat (limited to 'lib')
-rw-r--r--lib/WWW/Efa.pm18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/WWW/Efa.pm b/lib/WWW/Efa.pm
index b98a021..417fd6b 100644
--- a/lib/WWW/Efa.pm
+++ b/lib/WWW/Efa.pm
@@ -78,14 +78,24 @@ sub post_time {
sub post_date {
my ($post, $date) = @_;
+ my ($day, $month, $year) = split(/\./, $date);
- if ($date !~ /^ [0-3]? \d \. [01]? \d (?: | \. | \. (?: \d{4} ))? $/x) {
+ if (not defined $day or not length($day) or $day < 1 or $day > 31) {
die WWW::Efa::Error::Setup->new(
- 'date', $date, 'Must match DD.MM.[YYYY]'
+ 'date', $date, 'Invalid day'
);
}
- @{$post}{'itdDateDay', 'itdDateMonth', 'itdDateYear'} = split(/\./, $date);
- $post->{'itdDateYear'} //= (localtime(time))[5] + 1900;
+ if (not defined $month or not length($month) or $month < 1 or $month > 12) {
+ die WWW::Efa::Error::Setup->new(
+ 'date', $date, 'Invalid month'
+ );
+ }
+
+ if (not defined $year or not length($year)) {
+ $year = (localtime(time))[5] + 1900;
+ }
+
+ @{$post}{'itdDateDay', 'itdDateMonth', 'itdDateYear'} = ($day, $month, $year);
}
sub post_exclude {