Commits

Toby Inkster committed 5da2fa8

Fix bug where datetimes which occurred in the same second as the formatting function was run get interpreted as being in the future, when actually they are ever so slightly in the past.

  • Participants
  • Parent commits 6c82f40

Comments (0)

Files changed (2)

File lib/DateTimeX/Format/Ago.pm

 	Carp::croak(sprintf("%s doesn't do parsing", __PACKAGE__));
 }
 
+sub _now
+{
+	if ($INC{'Time/HiRes.pm'})
+	{
+		return DateTime->from_epoch(epoch => Time::HiRes::time());
+	}
+	return DateTime->now;
+}
+
 sub format_datetime
 {
 	my ($self, $datetime) = @_;
 	$self = $self->new unless blessed($self);
 	
-	my $now     = DateTime->now;
+	my $now     = $self->_now;
 	my $delta   = $now - $datetime;
 	my %strings = $self->_strings;
 	
+use Test::More;
+use DateTimeX::Format::Ago;
+
+eval { require Time::HiRes; 1 }
+	or plan skip_all => "Need Time::HiRes for this test";
+
+plan tests => 1;
+
+my $now = DateTime->from_epoch(epoch => scalar Time::HiRes::time());
+
+unlike(
+	DateTimeX::Format::Ago->new(language => 'en')->format_datetime($now),
+	qr{future}i,
+	);