-
Notifications
You must be signed in to change notification settings - Fork 2
/
Verify.pm
113 lines (81 loc) · 2.04 KB
/
Verify.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package Date::Verify;
use v5.10.0;
use strict;
use warnings;
use Exporter qw(import);
use Data::Validate qw(is_integer is_between);
use Date::Calc qw(:all);
our $VERSION = '1.0';
our @EXPORT_OK = qw(four_digit_year month_name month_number day_number);
sub four_digit_year {
my $year = shift;
if ($year !~ /\d{4}/) {
die "Sorry, please use the four digit year. Stopped";
}
return $year;
}
sub month_name {
my ($month) = @_;
if (is_integer($month)) {
if (is_between($month, 1, 12)) {
$month = Month_to_Text($month);
}
else {
die "Sorry, the month number you entered is invalid. Stopped";
}
}
else {
my $decoded_month = Decode_Month($month);
if ( $decoded_month ) {
$month = Month_to_Text($decoded_month);
}
else {
die "Sorry, your month name is a little short. Stopped";
}
}
return $month;
}
sub month_number {
my ($month) = @_;
if (is_integer($month)) {
if (is_between($month, 1, 12)) {
$month = $month;
}
else {
die "Sorry, the month number you entered is invalid. Stopped";
}
}
else {
my $decoded_month = Decode_Month($month);
if ( $decoded_month ) {
$month = $decoded_month;
}
else {
die "Sorry, your month name is a little short. Stopped";
}
}
return $month;
}
sub day_number {
my ($year, $month, $day) = @_;
my $days = Days_in_Month($year, month_number($month));
if ($day > $days) {
die "Sorry, there are only $days days in $month $year. Stopped";
}
return $day;
}
=pod
=encoding utf8
=NAME
B<Date::Verify> makes sure the input matches the date criteria.
=head1 VERSION
This document describes Date::Verify version 1.0.
=head1 DEPENDENCIES
Date::Verify depends on L<Exporter>, L<Date::Calc>, and L<Date::Validate>.
=head1 AUTHOR
Lady Aleena
=head1 LICENSE AND COPYRIGHT
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L<perlartistic>.
Copyright © 2020, Lady Aleena C<(aleena@cpan.org)>. All rights reserved.
=cut
1;