Revision 646cb2aa
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/Locale.pm | ||
---|---|---|
374 | 374 |
} |
375 | 375 |
|
376 | 376 |
sub parse_date_to_object { |
377 |
my $self = shift; |
|
378 |
my ($yy, $mm, $dd) = $self->parse_date(@_); |
|
377 |
my ($self, $string, %params) = @_; |
|
379 | 378 |
|
380 |
return $yy && $mm && $dd ? DateTime->new(year => $yy, month => $mm, day => $dd) : undef; |
|
379 |
$params{dateformat} ||= $::myconfig{dateformat} || 'yy-mm-dd'; |
|
380 |
$params{numberformat} ||= $::myconfig{numberformat} || '1,000.00'; |
|
381 |
my $num_separator = $params{numberformat} =~ m{,\d+$} ? ',' : '.'; |
|
382 |
|
|
383 |
my ($date_str, $time_str) = split m{\s+}, $string, 2; |
|
384 |
my ($yy, $mm, $dd) = $self->parse_date(\%params, $date_str); |
|
385 |
|
|
386 |
my $millisecond = 0; |
|
387 |
my ($hour, $minute, $second) = split m/:/, $time_str; |
|
388 |
($second, $millisecond) = split quotemeta($num_separator), $second, 2; |
|
389 |
$millisecond = substr $millisecond, 0, 3; |
|
390 |
$millisecond .= '0' x (3 - length $millisecond); |
|
391 |
|
|
392 |
return undef unless $yy && $mm && $dd; |
|
393 |
return DateTime->new(year => $yy, month => $mm, day => $dd, hour => $hour * 1, minute => $minute * 1, second => $second * 1, nanosecond => $millisecond * 1000000); |
|
381 | 394 |
} |
382 | 395 |
|
383 | 396 |
sub format_date_object_to_time { |
... | ... | |
644 | 657 |
|
645 | 658 |
TODO: Describe parse_date |
646 | 659 |
|
647 |
=item C<parse_date_to_object> |
|
660 |
=item C<parse_date_to_object $string, %params> |
|
661 |
|
|
662 |
Parses a date and optional timestamp in C<$string> and returns an |
|
663 |
instance of L<DateTime>. The date and number formats used are the ones |
|
664 |
the user has currently selected. They can be overriden by passing them |
|
665 |
in as parameters to this function, though. |
|
648 | 666 |
|
649 |
TODO: Describe parse_date_to_object
|
|
667 |
The time stamps can have up to millisecond precision.
|
|
650 | 668 |
|
651 | 669 |
=item C<quote_special_chars> |
652 | 670 |
|
Auch abrufbar als: Unified diff
Locale::parse_date_to_object: Unterstützung für volle Timestamps & explizite Formate
…und dafür Tests.