-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arthur Axel 'fREW' Schmidt
committed
Oct 18, 2013
1 parent
ef185b6
commit ca85705
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package DBIx::Class::Helper::Schema::DateTime; | ||
|
||
# ABSTRACT: DateTime helper | ||
|
||
use strict; | ||
use warnings; | ||
|
||
# VERSION | ||
|
||
sub datetime_parser { return shift->storage->datetime_parser } | ||
|
||
sub parse_datetime { return shift->datetime_parser->parse_datetime(@_) } | ||
|
||
sub format_datetime { return shift->datetime_parser->format_datetime(@_) } | ||
|
||
1; | ||
|
||
=head1 SYNOPSIS | ||
package MyApp::Schema; | ||
__PACKAGE__->load_components('Helper::Schema::DateTime'); | ||
... | ||
$schema->resultset('Book')->search({ | ||
written_on => $schema->format_datetime(DateTime->now) | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use lib 't/lib'; | ||
use Test::More; | ||
|
||
use TestSchema; | ||
use DateTime; | ||
|
||
TestSchema->load_components('Helper::Schema::DateTime'); | ||
my $schema = TestSchema->deploy_or_connect(); | ||
|
||
isa_ok($schema->datetime_parser, 'DateTime::Format::SQLite'); | ||
my $dt = DateTime->now; | ||
my $s = $schema->format_datetime($dt); | ||
is( | ||
$schema->format_datetime($schema->parse_datetime($s)), | ||
$schema->format_datetime($dt), | ||
'format_datetime and parse_datetime roundtrip', | ||
); | ||
|
||
done_testing; |