# Copyright (c) 1999-2006 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Year.pm,v 2.5 2008/10/10 15:53:21 moeller Exp $ package Bivio::Type::Year; use strict; use Bivio::Base 'Type.Integer'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.5 $ =~ /\d+/g); my($_DT) = __PACKAGE__->use('Type.DateTime'); sub WINDOW_SIZE { return 20; } sub from_literal { my($proto) = @_; my($res, $err) = shift->SUPER::from_literal(@_); return $err ? ($res, $err) : $res unless $err && $err == Bivio::TypeError->NUMBER_RANGE; # Compute with no range check ($res, $err) = Bivio::Type::Integer->from_literal(@_); return ($res, $err) if $err; return (undef, Bivio::TypeError->NUMBER_RANGE) unless $res >= 0 && $res < 100; return $proto->SUPER::from_literal( $res + int($proto->now / 100) * 100 - ($res <= $proto->now % 100 + $proto->WINDOW_SIZE ? 0 : 100), ); } sub get_default { return shift->now; } sub get_max { return '9999'; } sub get_min { return 100; } sub get_width { return 4; } sub now { return $_DT->now_as_year; } 1;