| 1 | package Data::Tersify::Plugin::DateTime; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | our $VERSION = '1.000'; | |||||||||
| 9 | 2 | $VERSION = eval $VERSION; | |||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Data::Tersify::Plugin::DateTime - tersify DateTime objects | ||||||||||
| 14 | |||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||
| 16 | |||||||||||
| 17 | use Data::Tersify; | ||||||||||
| 18 | print dumper(tersify({ now => DateTime->now })); | ||||||||||
| 19 | # Prints just today's date and time in yyyy-mm-ss hh:mm:ss format, | ||||||||||
| 20 | # rather than a full screen of DateTime internals | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | This class provides terse description for DateTime objects. | ||||||||||
| 25 | |||||||||||
| 26 | =head2 handles | ||||||||||
| 27 | |||||||||||
| 28 | It handles DateTime objects only. | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 1 | ▶ | sub handles { 'DateTime' } | ||||||||
|
Subroutine
handles: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | |||||||||||
| 34 | =head2 tersify | ||||||||||
| 35 | |||||||||||
| 36 | It summarises DateTime objects into human-readable representations, using | ||||||||||
| 37 | variants of the One True Date format. | ||||||||||
| 38 | |||||||||||
| 39 | If the time is 00:00:00, it returns I<yyyy-mm-dd>; if there's a more interesing | ||||||||||
| 40 | time, it returns I<yyyy-mm-dd hh:mm:ss>. If there's also a non-floating | ||||||||||
| 41 | timezone, it returns details of that timezone as well, so | ||||||||||
| 42 | I<yyyy-mm-dd hh:mm:ss Time/Zone>. | ||||||||||
| 43 | |||||||||||
| 44 | =cut | ||||||||||
| 45 | |||||||||||
| 46 | 4 | ▶ | sub tersify { | ||||||||
|
Subroutine
tersify: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 47 | 4 | my ($self, $datetime) = @_; | |||||||||
| 48 | |||||||||||
| 49 | 4 | my $terse = $datetime->ymd; | |||||||||
| 50 | 4 | ▶ | if ($datetime->hms ne '00:00:00') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 2 | $terse .= ' ' . $datetime->hms; | |||||||||
| 52 | 2 | ▶ | if ($datetime->time_zone->name ne 'floating') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | $terse .= ' ' . $datetime->time_zone->name; | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | 4 | return $terse; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 2 | 1; | |||||||||
| 60 | |||||||||||