CleanCode Perl Libraries
Multi-Lingual Library Maintainability
available: Perl not available: Java available: JavaScript not available: Certified
Class
not available: Testable
Class
not available: Standalone
Mode
not available: Diagnostic
Enabled

NAME

CGI::PageValidator::Plugin::Date - verifies a date consisting of day, month, and year components.

SYNOPSIS

(See the Note on Plugins in the CheckItem class for usage notes.)

        use CGI::PageValidator::Plugin::Date;
        $pluginObj=CGI::PageValidator::Plugin::Date->new($libItem,
          ["BirthDay","BirthMonth"], 1951, [15,3], "CGI::PageValidator::PluginLib");
        $pluginObj->examine();
        $errMsg = $pluginObj->getResult();

EXTENDS

CGI::PageValidator::Plugin

REQUIRES

Perl5.005, CGI::PageValidator::Plugin

KNOWN PLUGIN ATTACHMENTS

BirthYear

Dependent fields: BirthDay, BirthMonth

DESCRIPTION

This plugin examines an entered date first for validity as a date, i.e. it excludes April 31, Feb 29 in non-leap years, as well as nonsense dates like Dec 41st, etc. Next, depending upon the library specification, the date semantics may be checked further, so that if one wants a birth date, it must be before today. And if one needs a person to be of legal age to accept an agreement, then the birth date must be at least 18 years before today. Alternatively, if one is e.g. scheduling travel plans, the date must be after today.

Designed to be attached to a year field, this plugin has a dependency on two other fields, a day and a month field. You have some flexibility in naming the dependent fields and they may be specified in either order; of course, the name array order passed to the constructor must match the value array order. The dependent fields will be identified by the presence of the phrases "day" and "month" (case-independent) somewhere in the name list. So to check a birth date, "birthday" and "birthmonth" will work, as will "this-day" and "this-month" to check today's date, and so forth.

As indicated above, this plugin may simply validate that the year, month, and day values constitute any valid date, or you may additionally check for any of three constraints. To specify a constraint the item definition needs to specify the pluginOption property, which is merely an optional parameter field to pass to a plugin such as this. Here is the relevant fragment of a birth date definition:

        { name => "BirthYear",
          plugin => "Date",
          pluginOption => "earlier",
          dependsOn => ["BirthDay","BirthMonth"],
          . . .

The pluginOption property may have these values:

For a date before today

Specify a constraint containing any of the phrases "earlier" or "before" or "birth".

For a date after today

Specify a constraint containing any of the phrases "later" or "after".

Specify a constraint containing the phrase "legal".

BUGS

None

AUTHOR

Michael Sorens

VERSION

$Revision: 8 $ $Date: 2006-12-19 21:13:43 -0800 (Tue, 19 Dec 2006) $

SINCE

CleanCode 0.9


CleanCode Perl Libraries Copyright © 2001-2013 Michael Sorens - Revised 2013.06.30 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads