DateTime::Format::Builder::Parser::Regex — Regex based date parsing
| Use Case | Command | Description |
|---|---|---|
| 🔧 Create a parser from regex and params | my $parser = DateTime::Format::Builder->create_parser( regex => qr/.../, params => [qw( year month day )] ); | Parses a date string using named captures mapped to DateTime constructor keys |
| 📅 Add default values for missing fields | extra => { year => 2004, time_zone => "Australia/Sydney" } | Supplies default year or timezone when regex doesn't capture them |
| 🏗️ Custom constructor for parsing | constructor => [ 'ClassName', 'method' ] or constructor => sub { ... } | Use a custom class/method or coderef to build the DateTime object |
version 0.83
my $parser = DateTime::Format::Builder->create_parser(
regex => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
params => [qw( year month day hour minute second )],
);
In addition to the common keys, "Regex" supports:
Required. A regular expression that captures elements of the datetime string. Its presence indicates the specification belongs to this class.
Required. An arrayref of key names. Captures from the regex are mapped to these ($1 → first element, $2 → second, etc.) and handed to DateTime->new.
Optional. A hashref of extra arguments to DateTime->new. For example, default year or timezone:
extra => { year => 2004, time_zone => "Australia/Sydney" },
Either an arrayref or a coderef.
$p + extra.$self, $p, and extra. Equivalent to $self->$coderef( %{$p}, %{ $self->{extra} } );The method must return a valid DateTime object, or undef on failure.
Bugs may be submitted at https://github.com/houseabsolute/DateTime-Format-Builder/issues.
I am also usually active on IRC as 'autarch' on irc://irc.perl.org.
The source code repository for DateTime-Format-Builder can be found at https://github.com/houseabsolute/DateTime-Format-Builder.
This software is Copyright (c) 2020 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
The full text of the license can be found in the LICENSE file included with this distribution.
Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-06 18:00 @216.73.216.79
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format