File Coverage

blib/lib/Acme/CPANModules/FormattingDate.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Acme::CPANModules::FormattingDate;
2              
3 1     1   384449 use strict;
  1         5  
  1         513  
4              
5             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6             our $DATE = '2023-10-29'; # DATE
7             our $DIST = 'Acme-CPANModules-FormattingDate'; # DIST
8             our $VERSION = '0.002'; # VERSION
9              
10             my $text = <<'_';
11             **Overview**
12              
13             Date formatting modules can be categorized by their expected input format and
14             the formatting styles.
15              
16             Input format: Some modules accept date in the form of Unix epoch (an integer),
17             or a list of integer produced by running the epoch through the builtin gmtime()
18             or localtime() function. Some others might expect the date as
19             object. For formatting style: there's strftime in the core module,
20             and then there's the others.
21              
22             This list is organized using the latter criteria (formatting style).
23              
24             **strftime (and variants)**
25              
26             The module provides the `strftime()` routine which lets you format
27             using a template string containing sprintf-style conversions like `%Y` (for
28             4-digit year), `%m` (2-digit month number from 1-12), and so on. There's also
29             which provides an extension to this.
30              
31             You can actually add some modifiers for the conversions to set
32             width/zero-padding/alignment, like you can do with sprintf (e.g. `%03d`
33             supposing you want 3-digit day of month numbers). But this feature is
34             platform-dependent.
35              
36             **yyyy-mm-dd template**
37              
38             This "yyyy-mm-dd" (for lack of a better term) format is much more commonly used
39             in the general computing world, from spreadsheets to desktop environment clocks.
40             And this format is probably older than strftime. The template is more intuitive
41             to use for people as it gives a clear picture of how wide each component (and
42             the whole string) will be.
43              
44             There are some modules you can use to format dates using this style. First of
45             all there's . I find its API a little bit annoying, from the
46             verbose date component key names and inconsistent usage of plurals, to having to
47             use a separate method to "create the formatter" first.
48              
49             **PHP**
50              
51             PHP decided to invent its own date template format. Its `date()` function
52             accepts template string in which you specify single letter conversions like `Y'
53             (for 4-digit year), `y` (2-digit year), and so on. Some of the letters mean the
54             same like their counterpart in strftime, but some are different (examples: `i`,
55             `a`, `M`, and so on). The use of single letter means it's more concise, but the
56             format becomes unsuitable if you want to put other stuffs (like some string
57             alphabetical literals) in addition to date components.
58              
59             In Perl, you can use the to format dates using PHP `date()`
60             format.
61              
62             _
63              
64             our $LIST = {
65             summary => 'List of various methods to format dates',
66             description => $text,
67             tags => ['task'],
68             entries => [
69             map { +{module=>$_} }
70             do { my %seen; grep { !$seen{$_}++ }
71             ($text =~ //g)
72             }
73             ],
74             };
75              
76             1;
77             # ABSTRACT: List of various methods to format dates
78              
79             __END__