From 0cb0337175a65892949615e84c8d284be719abe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C5=8Dan?= Date: Wed, 25 Feb 2026 22:19:08 -0700 Subject: [PATCH] feat: support boost C++ timestamp format (%Y-%b-%d %H:%M:%S.%f) Add parsing support for the default C++ Boost timestamp format (e.g., "2002-Jul-22 10:00:00.000000"). This uses month name instead of month number in the date portion. Adds test cases for both abbreviated and full month names. Originally submitted as gbarr/perl-TimeDate#6 by @krya-kryak Co-Authored-By: Vladimir Kononov --- lib/Date/Parse.pm | 6 ++++++ t/date.t | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lib/Date/Parse.pm b/lib/Date/Parse.pm index b926e05..de6335d 100644 --- a/lib/Date/Parse.pm +++ b/lib/Date/Parse.pm @@ -92,6 +92,12 @@ sub { ($year,$month,$day,$hh,$mm,$ss,$frac) = ($1,$3-1,$4,$5,$7,$8,$9); } + # default C++ boost timestamp is effectively %Y-%b-%d %H:%M:%S.%f + # details: https://svn.boost.org/trac/boost/ticket/8839 + if ($dtstr =~ s/\s(\d{4})([-:]?)(\w{3,})\2(\d\d?)(?:[-Tt ](\d\d?)(?:([-:]?)(\d\d?)(?:\6(\d\d?)(?:[.,](\d+))?)?)?)?(?=\D)/ /) { + ($year,$month,$day,$hh,$mm,$ss,$frac) = ($1,$month{$3},$4,$5,$7,$8,$9); + } + unless (defined $hh) { if ($dtstr =~ s#[:\s](\d\d?):(\d\d?)(:(\d\d?)(?:\.\d+)?)?(z)?\s*(?:([ap])\.?m?\.?)?\s# #o) { ($hh,$mm,$ss) = ($1,$2,$4); diff --git a/t/date.t b/t/date.t index 14448bc..f34f4b5 100644 --- a/t/date.t +++ b/t/date.t @@ -150,6 +150,8 @@ Jul 22 10:00:00 UTC 2002 2002-07-22 10:00Z 2002-07-22 10:00 +100 2002-07-22 10:00 +0100 +2002-Jul-22 10:00:00.000000 +2002-July-22 10:00:00.000000 !; @data = split(/\n/, $data);