DateTime::Format -- strftime, strptime and other DateTime format related helpers for Perl 6
Switch branches/tags
Nothing to show
Clone or download
Timothy Totten
Timothy Totten See log, resolves #15.
Added 'Z' format option to strftime, uses '+0000' instead of 'Z' for UTC.
Updated RFC2822 format to use the new option.
Added a test specifically for this.
Latest commit 3f3c993 Mar 27, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/DateTime See log, resolves #15. Mar 27, 2018
t See log, resolves #15. Mar 27, 2018
.gitignore Add .precomp to the gitignore Oct 30, 2016
.travis.yml Remove the explicit build and test from travis conf Oct 30, 2016
META6.json Use modern META filename Apr 25, 2017
README.md See log, resolves #15. Mar 27, 2018

README.md

DateTime::Format

Description

Provides strftime(), strptime() (coming soon), and a few predetermined formats for use with both.

It also comes with some localizations for month and day names.

Convenience subroutines

These are exported by use DateTime::Format

strftime (Str $format, DateTime $dt, :$lang)

Format the DateTime object using the format as specified in the string.

If you don't specify the language, it uses the currently set default.

strptime (Str $timestamp, Str $format, :$lang)

Parse the string using the format as specified in the second string.

If you don't specify the language, it uses the currently set default.

set-datetime-format-lang (Str $code)

Set the default language to use. This can be 'en' (the default language), or any language you have added using one of the Localization libraries.

Formats

DateTime::Format::RFC2822

Parse or Stringify a DateTime in the RFC 2822 format.

  my $ts = 'Tue, 30 Apr 2013 13:02:10 -0700';
  my $rfc = DateTime::Format::RFC2822.new();
  my $dt  = $rfc.parse($ts);
  my $dt2 = $dt.utc();
  say ~$dt2;                   ## Tue, 30 Apr 2013 20:02:10 +0000

Localizations

The default localization is English, using the code 'en'. There is no loadable module for English, since it's strings are included by default in the DateTime::Format module.

The following are additional libraries that can add localizations to the DateTime::Format library. The languages will then be immediately usable.

  • DateTime::Format::Lang::FR -- French
  use DateTime::Format::Lang::FR;
  set-datetime-lang('fr');

  ## You can also specify the :lang<fr> parameter to the
  ## strftime(), strptime() subroutines, or the parse() and format()
  ## methods within a DateTime::Format::* subclass such as RFC2822.
  ## This overrides the language for a single call, rather than setting
  ## a default value.

TODO

  • Add strptime().
  • More bundled formats.
  • More localizations, and tests for them.

Authors

Anyone I'm missing that may have contributed, feel free to contact supernovus, and I'll add you to the credits.

License

Artistic License 2.0