Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Allow relative dates with time_format = relative
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Mar 10, 2016
1 parent b8bfa08 commit 242998f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"String::ShellQuote" : "0",
"Term::ANSIColor" : "1.04",
"Text::Wrap" : "0",
"Time::Duration" : "0",
"Time::Local" : "1.2100",
"perl" : "v5.14.0",
"strict" : "0",
Expand Down
2 changes: 2 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ my %WriteMakefileArgs = (
"String::ShellQuote" => 0,
"Term::ANSIColor" => "1.04",
"Text::Wrap" => 0,
"Time::Duration" => 0,
"Time::Local" => "1.2100",
"strict" => 0,
"warnings" => 0
Expand Down Expand Up @@ -83,6 +84,7 @@ my %FallbackPrereqs = (
"Test::More" => 0,
"Test::Output" => 0,
"Text::Wrap" => 0,
"Time::Duration" => 0,
"Time::Local" => "1.2100",
"strict" => 0,
"warnings" => 0
Expand Down
5 changes: 3 additions & 2 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ the timeline.

=item time_format

How to format dates in your timeline. This should be a strftime-like
format string. Defaults to I<%F %H:%M>.
How to format dates in your timeline. This should be a strftime-like format
string. As special case you can set it to I<relative> to get relative dates
like I<1 hour and 23 minutes ago>. Defaults to I<%F %H:%M>.

=item pre_tweet_hook

Expand Down
5 changes: 3 additions & 2 deletions bin/txtnix
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ the timeline.
=item time_format
How to format dates in your timeline. This should be a strftime-like
format string. Defaults to I<%F %H:%M>.
How to format dates in your timeline. This should be a strftime-like format
string. As special case you can set it to I<relative> to get relative dates
like I<1 hour and 23 minutes ago>. Defaults to I<%F %H:%M>.
=item pre_tweet_hook
Expand Down
4 changes: 4 additions & 0 deletions lib/App/txtnix/Tweet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package App::txtnix::Tweet;
use Mojo::Base -base;
use Mojo::ByteStream 'b';
use Mojo::Date;
use Time::Duration;
use POSIX ();

has [qw(source text)];
has timestamp => sub { Mojo::Date->new() };

sub strftime {
my ( $self, $format ) = @_;
if ( $format eq 'relative' ) {
return ago( ( int( ( time - $self->timestamp->epoch ) / 60 ) ) * 60 );
}
return POSIX::strftime( $format, localtime $self->timestamp->epoch );
}

Expand Down

0 comments on commit 242998f

Please sign in to comment.