App-FromUnixtime
view release on metacpan or search on metacpan
lib/App/FromUnixtime.pm view on Meta::CPAN
use IO::Interactive::Tiny;
use POSIX qw/strftime/;
use Config::CmdRC qw/.from_unixtimerc/;
use Exporter 'import';
our @EXPORT = qw/from_unixtime/;
our $VERSION = '0.17';
our $MAYBE_UNIXTIME = join '|', (
'created_(?:at|on)',
'updated_(?:at|on)',
'released_(?:at|on)',
'closed_(?:at|on)',
'published_(?:at|on)',
'expired_(?:at|on)',
'date',
'unixtime',
'_time',
);
our $DEFAULT_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S %z';
script/from_unixtime view on Meta::CPAN
$ from_unixtime 1419702037
1419702037(Sun, 28 Dec 2014 02:40:37 +0900)
or filter unixtime suitably
$ cat sql_result
id 1
value 1419702037
created_at 1419702037
updated_at 1419702037
$ cat sql_result | from_unixtime
id 1
value 1419702037
created_at 1419702037(Sun, 28 Dec 2014 02:40:37 +0900)
updated_at 1419702037(Sun, 28 Dec 2014 02:40:37 +0900)
=head2 OPTIONS
-f --format date format // '%a, %d %b %Y %H:%M:%S %z'
--start-bracket change start bracket // '('
--end-bracket change end bracket // ')'
--re additional column condition
--no-re no replace condition(this option has overriding priority)
script/from_unixtime view on Meta::CPAN
--replace not to add the date to unixtime but to be replaced it
=head3 EXAMPLES
To edit the date format.
$ cat sql_result | from_unixtime --format '%Y/%m/%d %H:%M:%S'
id 1
value 1419702037
created_at 1419702037(2014/12/28 02:40:37)
updated_at 1419702037(2014/12/28 02:40:37)
Also replace C<value> line with '--re' option.
$ cat sql_result | from_unixtime --re value
id 1
value 1419702037(Sun, 28 Dec 2014 02:40:37 +0900)
created_at 1419702037(Sun, 28 Dec 2014 02:40:37 +0900)
updated_at 1419702037(Sun, 28 Dec 2014 02:40:37 +0900)
If you do not want to replace then you use '--no-re' option
$ cat sql_result | from_unixtime --no-re updated
id 1
value 1419702037
created_at 1419702037(Sun, 28 Dec 2014 02:40:37 +0900)
updated_at 1419702037
=head2 CONFIGURATION
`from_unixtime` command will look for a configuration file before reading its command line parameters. This function depends on L<Config::CmdRC>.
The configuration file is `.from_unixtimerc`. And the location of a configuration file is C</etc> or C<$HOME> but if the C<CMDRC_DIR> environment variable is set, `from_unixtime` will look for configuration file in that directory or C<current directo...
A sample configuration file might read:
t/04_function.t view on Meta::CPAN
*App::FromUnixtime::RC = sub { +{} };
{
like from_unixtime(1419702037), qr/1419702037\([^\)]+\)/;
like from_unixtime('date 1419702037'), qr/date 1419702037\([^\)]+\)/;
}
{
my $replaced = from_unixtime(<<"_TEXT_");
created_at 1419702037
updated_at 1419702037
_TEXT_
like $replaced, qr/created_at 1419702037\([^\)]+\)/;
like $replaced, qr/updated_at 1419702037\([^\)]+\)/;
}
{
my $replaced = from_unixtime(
'date 1419702037',
'--start-bracket' => '[',
'--end-bracket' => ']',
);
like $replaced, qr/date 1419702037\[[^\]]+\]/;
( run in 0.458 second using v1.01-cache-2.11-cpan-05444aca049 )