+sub parse_date_to_object {
+ my ($self, $string, %params) = @_;
+
+ return undef if !defined $string;
+
+ return DateTime->today_local if lc($string) eq 'today';
+ return DateTime->today_local->subtract(days => 1) if lc($string) eq 'yesterday';
+
+ $params{dateformat} ||= $::myconfig{dateformat} || 'yy-mm-dd';
+ $params{numberformat} ||= $::myconfig{numberformat} || '1,000.00';
+ my $num_separator = $params{numberformat} =~ m{,\d+$} ? ',' : '.';
+
+ my ($date_str, $time_str) = split m{\s+}, $string, 2;
+ my ($yy, $mm, $dd) = $self->parse_date(\%params, $date_str);
+
+ my ($hour, $minute, $second) = split m/:/, ($time_str || '');
+ $second ||= '0';
+
+ ($second, my $millisecond) = split quotemeta($num_separator), $second, 2;
+ $_ ||= 0 for ($hour, $minute, $millisecond);
+
+ $millisecond = substr $millisecond, 0, 3;
+ $millisecond .= '0' x (3 - length $millisecond);
+
+ return undef unless $yy && $mm && $dd;
+ return DateTime->new(year => $yy, month => $mm, day => $dd, hour => $hour * 1, minute => $minute * 1, second => $second * 1, nanosecond => $millisecond * 1000000);
+}
+
+sub format_date_object_to_time {
+ my ($self, $datetime, %params) = @_;
+
+ my $format = $::myconfig{timeformat} || 'hh:mm';
+ $format =~ s/hh/\%H/;
+ $format =~ s/mm/\%M/;
+ $format =~ s/ss/\%S/;
+
+ return $datetime->strftime($format);
+}
+
+sub format_date_object {
+ my ($self, $datetime, %params) = @_;
+
+ my $format = $params{dateformat} || $::myconfig{dateformat} || 'yyyy-mm-dd';
+ my $num_separator = ($params{numberformat} || $::myconfig{numberformat} || '1,000.00') =~ m{,\d+$} ? ',' : '.';
+ $format =~ s/yy(?:yy)?/\%Y/;
+ $format =~ s/mm/\%m/;
+ $format =~ s/dd/\%d/;
+
+ my $precision = $params{precision} || 'day';
+ $precision =~ s/s$//;
+ my %precision_spec_map = (
+ millisecond => '%H:%M:%S' . $num_separator . '%3N',
+ second => '%H:%M:%S',
+ minute => '%H:%M',
+ hour => '%H',
+ );
+
+ $format .= ' ' . $precision_spec_map{$precision} if $precision_spec_map{$precision};
+
+ return $datetime->strftime($format);
+}
+