Skip to content
This repository has been archived by the owner on Dec 11, 2017. It is now read-only.

Commit

Permalink
improved to_datetime method in Mango::BSON::Time to be able to handle…
Browse files Browse the repository at this point in the history
… higher precision times
  • Loading branch information
kraih committed Aug 23, 2014
1 parent b419bf2 commit 38b9a30
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

1.08 2014-08-24
- Improved to_datetime method in Mango::BSON::Time to be able to handle
higher precision times.

1.07 2014-08-23
- Fixed small JSON serialization bug in Mango::BSON::Time.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ WriteMakefile(
},
no_index => {directory => ['t']}
},
PREREQ_PM => {Mojolicious => '5.32'},
PREREQ_PM => {Mojolicious => '5.33'},
test => {TESTS => 't/*.t t/*/*.t'}
);
2 changes: 1 addition & 1 deletion lib/Mango/BSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ defaults to milliseconds since the UNIX epoch.
# "1360626536.748"
bson_time(1360626536748)->to_epoch;
# "2013-02-11T23:48:56Z"
# "2013-02-11T23:48:56.748Z"
bson_time(1360626536748)->to_datetime;
=head2 bson_true
Expand Down
2 changes: 1 addition & 1 deletion lib/Mango/BSON/Time.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sub new { shift->SUPER::new(time => shift // int(time * 1000)) }

sub TO_JSON { 0 + shift->{time} }

sub to_datetime { Mojo::Date->new(int shift->to_epoch)->to_datetime }
sub to_datetime { Mojo::Date->new(shift->to_epoch)->to_datetime }

sub to_epoch { shift->to_string / 1000 }

Expand Down
2 changes: 1 addition & 1 deletion t/bson.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ is length int bson_time->to_epoch, length time, 'right length';
is substr(bson_time->to_epoch, 0, 5), substr(time, 0, 5), 'same start';
is bson_time(1360626536748), 1360626536748, 'right epoch milliseconds';
is bson_time(1360626536748)->to_epoch, 1360626536.748, 'right epoch seconds';
is bson_time(1360626536748)->to_datetime, '2013-02-11T23:48:56Z',
is bson_time(1360626536748)->to_datetime, '2013-02-11T23:48:56.748Z',
'right format';

# Empty document
Expand Down

0 comments on commit 38b9a30

Please sign in to comment.