%doc>
Example:
<& /elements/tr-input_date-field,
{
'name' => 'field_name',
'value' => $current_value,
'label' => 'Label',
#optional
'format' => '%m/%d/%Y', #overrides date_format config
'usedatetime' => 1, #use DateTime->strftime to format the date
# instead of Date::Format->time2str
'noinit' => 1, #first one on the page is enough
},
&>
%doc>
% unless ( $noinit ) {
% }
<% $label %> |
|
<%init>
my($name, $value, $label, $format, $usedatetime, $noinit);
if ( ref($_[0]) ) {
my $opt = shift;
$name = $opt->{'name'};
$value = $opt->{'value'};
$label = $opt->{'label'};
$format = $opt->{'format'};
$usedatetime = $opt->{'usedatetime'};
$noinit = $opt->{'noinit'};
} else {
($name, $value, $label, $format, $usedatetime) = @_;
}
my $conf = new FS::Conf;
$format ||= $conf->config('date_format') || '%m/%d/%Y';
$label = $name unless $label;
if ( $value =~ /\S/ ) {
if ( $usedatetime ) {
my $dt = DateTime->from_epoch(epoch => $value, time_zone => 'floating');
$value = $dt->strftime($format);
} elsif ( $value =~ /^\d+$/ ) {
$value = time2str($format, $value);
}
} else {
$value = '';
}
%init>