I'd suggst implementing http://search.cpan.org/dist/DateTime-Format-Natural/lib/DateTime/Format/Natural/Lang/EN.pm with this feature.

Am 14.02.2008 um 20:43 schrieb Brian Cassidy:

This may open a can of worms, but I've refactored the defaults for the Date element to allow the string "today" to correspond to DateTime->today().

This seemed like a sensible option to allow -- though i know one could go overboard with textual representations.

See attachment.

-Brian
=== lib/HTML/FormFu/Element/Date.pm
==================================================================
--- lib/HTML/FormFu/Element/Date.pm     (revision 29417)
+++ lib/HTML/FormFu/Element/Date.pm     (local)
@@ -109,22 +109,21 @@
    my $default = $self->default;

    if ( defined $default ) {
+        my $is_blessed = blessed( $default );

-        if ( blessed($default) && $default->isa('DateTime') ) {
-            $self->day->{default}   = $default->day;
-            $self->month->{default} = $default->month;
-            $self->year->{default}  = $default->year;
+ if( "$default" eq 'today' ) { # $default needs stringification
+            $default = DateTime->today;
        }
-        else {
+ elsif ( !$is_blessed || ( $is_blessed && !$default- >isa('DateTime') ) ) {
            my $builder = DateTime::Format::Builder->new;
            $builder->parser( { strptime => $self->strftime } );

-            my $dt = $builder->parse_datetime($default);
-
-            $self->day->{default}   = $dt->day;
-            $self->month->{default} = $dt->month;
-            $self->year->{default}  = $dt->year;
+            $default = $builder->parse_datetime($default);
        }
+
+        $self->day->{default}   = $default->day;
+        $self->month->{default} = $default->month;
+        $self->year->{default}  = $default->year;
    }

    return;
_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu


_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to