| 1 | package Rose::DB::Object::Metadata::Column::DatetimeYearToFraction; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use Rose::DB::Object::Metadata::Column::Datetime; | ||
| 6 | our @ISA = qw(Rose::DB::Object::Metadata::Column::Datetime); | ||
| 7 | |||
| 8 | our $VERSION = '0.788'; | ||
| 9 | |||
| 10 | sub type { 'datetime year to fraction' } | ||
| 11 | |||
| 12 | sub should_inline_value | ||
| 13 | { | ||
| 14 | my($self, $db, $value) = @_; | ||
| 15 | no warnings 'uninitialized'; | ||
| 16 | return (($db->validate_datetime_year_to_fraction_keyword($value) && $db->should_inline_datetime_keyword($value)) || | ||
| 17 | ($db->keyword_function_calls && $value =~ /^\w+\(.*\)$/)) ? 1 : 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub parse_value | ||
| 21 | { | ||
| 22 | my($self, $db) = (shift, shift); | ||
| 23 | |||
| 24 | $self->parse_error(undef); | ||
| 25 | |||
| 26 | my $dt = $db->parse_datetime_year_to_fraction(@_); | ||
| 27 | |||
| 28 | if($dt) | ||
| 29 | { | ||
| 30 | $dt->set_time_zone($self->time_zone || $db->server_time_zone) | ||
| 31 | if(UNIVERSAL::isa($dt, 'DateTime')); | ||
| 32 | } | ||
| 33 | else | ||
| 34 | { | ||
| 35 | $dt = Rose::DateTime::Util::parse_date($_[0], $self->time_zone || $db->server_time_zone); | ||
| 36 | |||
| 37 | if(my $error = Rose::DateTime::Util->error) | ||
| 38 | { | ||
| 39 | $self->parse_error("Could not parse value '$_[0]' for column $self: $error") | ||
| 40 | if(defined $_[0]); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | return $dt; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub format_value { shift; shift->format_datetime_year_to_fraction(@_) } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ |