396 |
396 |
return $yy && $mm && $dd ? DateTime->new(year => $yy, month => $mm, day => $dd) : undef;
|
397 |
397 |
}
|
398 |
398 |
|
|
399 |
sub format_date_object {
|
|
400 |
my ($self, $datetime, %params) = @_;
|
|
401 |
|
|
402 |
my $format = $::myconfig{dateformat} || 'yyyy-mm-dd';
|
|
403 |
$format =~ s/yyyy/\%Y/;
|
|
404 |
$format =~ s/yy/\%y/;
|
|
405 |
$format =~ s/mm/\%m/;
|
|
406 |
$format =~ s/dd/\%d/;
|
|
407 |
|
|
408 |
my $precision = $params{precision} || 'day';
|
|
409 |
$precision =~ s/s$//;
|
|
410 |
my %precision_spec_map = (
|
|
411 |
second => '%H:%M:%S',
|
|
412 |
minute => '%H:%M',
|
|
413 |
hour => '%H',
|
|
414 |
);
|
|
415 |
|
|
416 |
$format .= ' ' . $precision_spec_map{$precision} if $precision_spec_map{$precision};
|
|
417 |
|
|
418 |
return $datetime->strftime($format);
|
|
419 |
}
|
|
420 |
|
399 |
421 |
sub reformat_date {
|
400 |
422 |
$main::lxdebug->enter_sub(2);
|
401 |
423 |
|
... | ... | |
516 |
538 |
}
|
517 |
539 |
|
518 |
540 |
1;
|
|
541 |
__END__
|
|
542 |
|
|
543 |
=pod
|
|
544 |
|
|
545 |
=encoding utf8
|
|
546 |
|
|
547 |
=head1 NAME
|
|
548 |
|
|
549 |
Locale - Functions for dealing with locale-dependant information
|
|
550 |
|
|
551 |
=head1 SYNOPSIS
|
|
552 |
|
|
553 |
use Locale;
|
|
554 |
use DateTime;
|
|
555 |
|
|
556 |
my $locale = Locale->new('de');
|
|
557 |
my $now = DateTime->now_local;
|
|
558 |
print "Current date and time: ", $::locale->format_date_object($now, precision => 'second'), "\n";
|
|
559 |
|
|
560 |
=head1 OVERVIEW
|
|
561 |
|
|
562 |
TODO: write overview
|
|
563 |
|
|
564 |
=head1 FUNCTIONS
|
|
565 |
|
|
566 |
=over 4
|
|
567 |
|
|
568 |
=item C<date>
|
|
569 |
|
|
570 |
TODO: Describe date
|
|
571 |
|
|
572 |
=item C<findsub>
|
|
573 |
|
|
574 |
TODO: Describe findsub
|
|
575 |
|
|
576 |
=item C<format_date>
|
|
577 |
|
|
578 |
TODO: Describe format_date
|
|
579 |
|
|
580 |
=item C<format_date_object $datetime, %params>
|
|
581 |
|
|
582 |
Formats the C<$datetime> object accoring to the user's locale setting.
|
|
583 |
|
|
584 |
The parameter C<precision> can control whether or not the time
|
|
585 |
component is formatted as well:
|
|
586 |
|
|
587 |
=over 4
|
|
588 |
|
|
589 |
=item * C<day>
|
|
590 |
|
|
591 |
Only format the year, month and day. This is also the default.
|
|
592 |
|
|
593 |
=item * C<hour>
|
|
594 |
|
|
595 |
Add the hour to the date.
|
|
596 |
|
|
597 |
=item * C<minute>
|
|
598 |
|
|
599 |
Add hour:minute to the date.
|
|
600 |
|
|
601 |
=item * C<second>
|
|
602 |
|
|
603 |
Add hour:minute:second to the date.
|
|
604 |
|
|
605 |
=back
|
|
606 |
|
|
607 |
=item C<get_local_time_zone>
|
|
608 |
|
|
609 |
TODO: Describe get_local_time_zone
|
|
610 |
|
|
611 |
=item C<is_utf8>
|
|
612 |
|
|
613 |
TODO: Describe is_utf8
|
|
614 |
|
|
615 |
=item C<lang_to_locale>
|
|
616 |
|
|
617 |
TODO: Describe lang_to_locale
|
|
618 |
|
|
619 |
=item C<new>
|
|
620 |
|
|
621 |
TODO: Describe new
|
|
622 |
|
|
623 |
=item C<parse_date>
|
|
624 |
|
|
625 |
TODO: Describe parse_date
|
|
626 |
|
|
627 |
=item C<parse_date_to_object>
|
|
628 |
|
|
629 |
TODO: Describe parse_date_to_object
|
|
630 |
|
|
631 |
=item C<quote_special_chars>
|
|
632 |
|
|
633 |
TODO: Describe quote_special_chars
|
|
634 |
|
|
635 |
=item C<raw_io_active>
|
|
636 |
|
|
637 |
TODO: Describe raw_io_active
|
|
638 |
|
|
639 |
=item C<reformat_date>
|
|
640 |
|
|
641 |
TODO: Describe reformat_date
|
|
642 |
|
|
643 |
=item C<remap_special_chars>
|
|
644 |
|
|
645 |
TODO: Describe remap_special_chars
|
|
646 |
|
|
647 |
=item C<restore_numberformat>
|
|
648 |
|
|
649 |
TODO: Describe restore_numberformat
|
|
650 |
|
|
651 |
=item C<set_numberformat_wo_thousands_separator>
|
|
652 |
|
|
653 |
TODO: Describe set_numberformat_wo_thousands_separator
|
|
654 |
|
|
655 |
=item C<text>
|
|
656 |
|
|
657 |
TODO: Describe text
|
|
658 |
|
|
659 |
=item C<unquote_special_chars>
|
|
660 |
|
|
661 |
TODO: Describe unquote_special_chars
|
|
662 |
|
|
663 |
=item C<with_raw_io>
|
|
664 |
|
|
665 |
TODO: Describe with_raw_io
|
|
666 |
|
|
667 |
=back
|
|
668 |
|
|
669 |
=head1 BUGS
|
|
670 |
|
|
671 |
Nothing here yet.
|
|
672 |
|
|
673 |
=head1 AUTHOR
|
|
674 |
|
|
675 |
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
|
|
676 |
|
|
677 |
=cut
|
Locale: Methode format_date_object zum Formatieren von DateTime-Instanzen; Doku
Unterstützt auch Ausgabe von Stunden, Minuten, Sekunden mittels eines
Parameters 'precision'.