[Bast-commits] r8089 - in ironman: IronMan-Web
IronMan-Web/lib/IronMan/Web/Controller
IronMan-Web/root/archive plagger/lib/IronMan/Schema/ResultSet
fade at dev.catalyst.perl.org
fade at dev.catalyst.perl.org
Sat Dec 12 20:43:20 GMT 2009
Author: fade
Date: 2009-12-12 20:43:20 +0000 (Sat, 12 Dec 2009)
New Revision: 8089
Modified:
ironman/IronMan-Web/Makefile.PL
ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm
ironman/IronMan-Web/root/archive/day.tt
ironman/IronMan-Web/root/archive/month.tt
ironman/plagger/lib/IronMan/Schema/ResultSet/Post.pm
Log:
create the DateTime object in the controller as we need it for other things
Modified: ironman/IronMan-Web/Makefile.PL
===================================================================
--- ironman/IronMan-Web/Makefile.PL 2009-12-12 20:19:06 UTC (rev 8088)
+++ ironman/IronMan-Web/Makefile.PL 2009-12-12 20:43:20 UTC (rev 8089)
@@ -16,6 +16,7 @@
requires 'Email::Valid';
requires 'LWP::Simple';
requires 'XML::Feed';
+requires 'DateTime';
catalyst;
Modified: ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm
===================================================================
--- ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm 2009-12-12 20:19:06 UTC (rev 8088)
+++ ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm 2009-12-12 20:43:20 UTC (rev 8089)
@@ -4,6 +4,8 @@
BEGIN {extends 'Catalyst::Controller'; }
+use DateTime;
+
=head1 NAME
IronMan::Web::Controller::Archive - Catalyst Controller
@@ -47,10 +49,18 @@
sub month :Path :Args(2) {
my ( $self, $c, $year, $month ) = @_;
- my $posts = $c->model('FeedDB::Post')->posts_for_month($month, $year);
+ my $dt_month = DateTime->new(
+ 'year' => $year,
+ 'month' => $month,
+ 'day' => 1,
+ 'hour' => 0,
+ 'minute' => 0,
+ 'second' => 0,
+ );
+
+ my $posts = $c->model('FeedDB::Post')->posts_for_month($dt_month);
$c->stash( 'posts' => $posts );
- $c->stash( 'year' => $year );
- $c->stash( 'month' => $month );
+ $c->stash( 'month' => $dt_month );
}
@@ -61,11 +71,18 @@
sub day :Path :Args(3) {
my ( $self, $c, $year, $month, $day ) = @_;
- my $posts = $c->model('FeedDB::Post')->posts_for_day($day, $month, $year);
+ my $dt_day = DateTime->new(
+ 'year' => $year,
+ 'month' => $month,
+ 'day' => $day,
+ 'hour' => 0,
+ 'minute' => 0,
+ 'second' => 0,
+ );
+
+ my $posts = $c->model('FeedDB::Post')->posts_for_day($dt_day);
$c->stash( 'posts' => $posts );
- $c->stash( 'year' => $year );
- $c->stash( 'month' => $month );
- $c->stash( 'day' => $day );
+ $c->stash( 'day' => $dt_day );
}
=head1 AUTHOR
Modified: ironman/IronMan-Web/root/archive/day.tt
===================================================================
--- ironman/IronMan-Web/root/archive/day.tt 2009-12-12 20:19:06 UTC (rev 8088)
+++ ironman/IronMan-Web/root/archive/day.tt 2009-12-12 20:43:20 UTC (rev 8089)
@@ -1,5 +1,5 @@
-Daily archive for [% day %] [% month %] [% year %]
+Daily archive for [% day %]
[% FOREACH post IN posts.all %]
Modified: ironman/IronMan-Web/root/archive/month.tt
===================================================================
--- ironman/IronMan-Web/root/archive/month.tt 2009-12-12 20:19:06 UTC (rev 8088)
+++ ironman/IronMan-Web/root/archive/month.tt 2009-12-12 20:43:20 UTC (rev 8089)
@@ -1,5 +1,5 @@
-Monthly archive for [% month %] [% year %]
+Monthly archive for [% month %]
[% FOREACH post IN posts.all %]
Modified: ironman/plagger/lib/IronMan/Schema/ResultSet/Post.pm
===================================================================
--- ironman/plagger/lib/IronMan/Schema/ResultSet/Post.pm 2009-12-12 20:19:06 UTC (rev 8088)
+++ ironman/plagger/lib/IronMan/Schema/ResultSet/Post.pm 2009-12-12 20:43:20 UTC (rev 8089)
@@ -9,64 +9,59 @@
=head2 posts_for_day
-posts_for_day($day, $month, $year)
+posts_for_day($datetime)
Returns a resultset containing all posts for a particular date.
=cut
sub posts_for_day {
- my ($self, $day, $month, $year) = @_;
+ my ($self, $dt_day) = @_;
- my $dt_parser = $self->result_source->storage->datetime_parser;
+ my $day_start = $dt_day->clone()->truncate( 'to' => 'day');
- my $day_start = DateTime->new(
- 'year' => $year,
- 'month' => $month,
- 'day' => $day,
- 'hour' => 0,
- 'minute' => 0,
- 'second' => 0,
- );
-
my $day_end = $day_start->clone()->add( 'days' => 1 )->subtract( 'seconds' => 1 );
- return $self->search({
- 'posted_on' => { '-between' => [ map $dt_parser->format_datetime($_), $day_start, $day_end ] },
- },{
- 'order_by' => \'posted_on DESC',
- });
+ return $self->posts_for_daterange($day_start, $day_end);
}
=head2 posts_for_month
-posts_for_month($month, $year)
+posts_for_month($datetime)
Returns a resultset containing all posts for a particular month.
=cut
sub posts_for_month {
- my ($self, $month, $year) = @_;
+ my ($self, $dt_month) = @_;
- my $dt_parser = $self->result_source->storage->datetime_parser;
-
- my $month_start = DateTime->new(
- 'year' => $year,
- 'month' => $month,
- 'day' => 1,
- 'hour' => 0,
- 'minute' => 0,
- 'second' => 0,
- );
-
+ my $month_start = $dt_month->clone()->truncate( 'to' => 'month');
+
my $month_end = $month_start->clone()->add( 'months' => 1 )->subtract( 'seconds' => 1 );
-
+
+ return $self->posts_for_daterange($month_start, $month_end);
+}
+
+=head2 posts_for_month
+
+posts_for_daterange($datetime_start,$datetime_end)
+
+Returns a resultset containing all posts between two datetime objects.
+
+=cut
+
+sub posts_for_daterange {
+ my ($self, $dt_start, $dt_end ) = @_;
+
+ my $dt_parser = $self->result_source->storage->datetime_parser;
+
return $self->search({
- 'posted_on' => { '-between' => [ map $dt_parser->format_datetime($_), $month_start, $month_end ] },
+ 'posted_on' => { '-between' => [ map $dt_parser->format_datetime($_), $dt_start, $dt_end ] },
},{
'order_by' => \'posted_on DESC',
});
+
}
1;
More information about the Bast-commits
mailing list