| 1 | package Sculptor::Date; | ||||||||||
| 2 | |||||||||||
| 3 | 8 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | @EXPORT_OK = qw(date_to_number number_to_date); | |||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 8 | ▶ | use Date::Calc qw/Add_Delta_Days Delta_Days/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Sculptor::Date - Convert Sculptor 4GL dates | ||||||||||
| 14 | |||||||||||
| 15 | =head1 VERSION | ||||||||||
| 16 | |||||||||||
| 17 | Version 0.02 | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 8 | our $VERSION = '0.02'; | |||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||
| 26 | |||||||||||
| 27 | This module converts between ISO dates and Sculptor 4GL day numbers. It has | ||||||||||
| 28 | been tested with dates from Sculptor Release 2.5b. | ||||||||||
| 29 | |||||||||||
| 30 | Sculptor 4GL is a programming language owned by MPD. For more information on | ||||||||||
| 31 | Sculptor, you can visit http://www.sculptor.co.uk/ | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | use Sculptor::Date qw/date_to_number number_to_date/; | ||||||||||
| 35 | |||||||||||
| 36 | my $date = '2010-01-30'; | ||||||||||
| 37 | |||||||||||
| 38 | my $day_number = date_to_number($date); | ||||||||||
| 39 | |||||||||||
| 40 | my $new_date = number_to_date($day_number); | ||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | =head1 EXPORT | ||||||||||
| 44 | |||||||||||
| 45 | date_to_number, number_to_date | ||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | =head1 FUNCTIONS | ||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | =head2 date_to_number | ||||||||||
| 53 | |||||||||||
| 54 | Converts an ISO 8601 date (YYYY-MM-DD) to a Sculptor day number. | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 6 | ▶ | sub date_to_number { | ||||||||
|
Subroutine
date_to_number: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 59 | |||||||||||
| 60 | 6 | my $date = shift; | |||||||||
| 61 | |||||||||||
| 62 | 6 | ▶ | if ( $date =~ /\d\d\d\d-\d\d-\d\d/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | 6 | my ($y,$m,$d) = split /-/, $date; | |||||||||
| 65 | 6 | my @start = (1970,1,1); | |||||||||
| 66 | 6 | my $delta = Delta_Days($start[0],$start[1],$start[2],$y,$m,$d); | |||||||||
| 67 | 6 | my $japfirst = 719163; | |||||||||
| 68 | 6 | my $dayno = $japfirst + $delta; | |||||||||
| 69 | |||||||||||
| 70 | 6 | return $dayno; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 0 | confess "Malformed date provided to subroutine: [$date]."; | |||||||||
| 74 | |||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | =head2 number_to_date | ||||||||||
| 80 | |||||||||||
| 81 | Converts a Sculptor day number to an ISO date. | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | 6 | ▶ | sub number_to_date { | ||||||||
|
Subroutine
number_to_date: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 86 | |||||||||||
| 87 | 6 | my $sculptor_date = shift; | |||||||||
| 88 | |||||||||||
| 89 | 6 | ▶ | unless ( $sculptor_date =~ m/^\d{1,6}$/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | croak "Incorrect or implausible day number [$sculptor_date]."; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 6 | my @start = (1970,1,1); | |||||||||
| 94 | 6 | my $sculptor_first = 719163; | |||||||||
| 95 | 6 | my $diff = $sculptor_date - $sculptor_first; | |||||||||
| 96 | 6 | my @date = Add_Delta_Days(@start,$diff); | |||||||||
| 97 | 6 | my $date = sprintf("%04d-%02d-%02d", @date); | |||||||||
| 98 | |||||||||||
| 99 | 6 | return $date; | |||||||||
| 100 | |||||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | =head1 AUTHOR | ||||||||||
| 106 | |||||||||||
| 107 | Damon Allen Davison, C<< <allolex at cpan.org> >> | ||||||||||
| 108 | |||||||||||
| 109 | |||||||||||
| 110 | |||||||||||
| 111 | =head1 BUGS | ||||||||||
| 112 | |||||||||||
| 113 | Please report any bugs or feature requests to | ||||||||||
| 114 | C<bug-sculptor-date at rt.cpan.org>, | ||||||||||
| 115 | or through the web interface at | ||||||||||
| 116 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sculptor-Date>. | ||||||||||
| 117 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 118 | your bug as I make changes. | ||||||||||
| 119 | |||||||||||
| 120 | |||||||||||
| 121 | |||||||||||
| 122 | =head1 SUPPORT | ||||||||||
| 123 | |||||||||||
| 124 | You can find documentation for this module with the perldoc command. | ||||||||||
| 125 | |||||||||||
| 126 | perldoc Sculptor::Date | ||||||||||
| 127 | |||||||||||
| 128 | |||||||||||
| 129 | You can also look for information at: | ||||||||||
| 130 | |||||||||||
| 131 | =over 4 | ||||||||||
| 132 | |||||||||||
| 133 | =item * RT: CPAN's request tracker | ||||||||||
| 134 | |||||||||||
| 135 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sculptor-Date> | ||||||||||
| 136 | |||||||||||
| 137 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 138 | |||||||||||
| 139 | L<http://annocpan.org/dist/Sculptor-Date> | ||||||||||
| 140 | |||||||||||
| 141 | =item * CPAN Ratings | ||||||||||
| 142 | |||||||||||
| 143 | L<http://cpanratings.perl.org/d/Sculptor-Date> | ||||||||||
| 144 | |||||||||||
| 145 | =item * Search CPAN | ||||||||||
| 146 | |||||||||||
| 147 | L<http://search.cpan.org/dist/Sculptor-Date/> | ||||||||||
| 148 | |||||||||||
| 149 | =back | ||||||||||
| 150 | |||||||||||
| 151 | |||||||||||
| 152 | |||||||||||
| 153 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 154 | |||||||||||
| 155 | Copyright 2010 Damon Allen Davison, all rights reserved. | ||||||||||
| 156 | |||||||||||
| 157 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 158 | under the same terms as Perl itself. | ||||||||||
| 159 | |||||||||||
| 160 | |||||||||||
| 161 | =cut | ||||||||||
| 162 | |||||||||||
| 163 | 8 | 1; # End of Sculptor::Date | |||||||||