Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is a small Perl script to calculate the number of the week from any given date, (given in the ISO 8601 format), or uses today's date if no date is specified. It was written just to scratch an itch I had in the past, when I frequently needed to know the number of the week for planning purposes.

See the POD for more information about how it works. This is the first time I share my code here on PerlMonks, and any comments, suggestions or improvements are greatly appreciated.

#!/usr/bin/perl -w # # calcweek.pl - Calculate the week number from any given date, # or the default, if no date is given. # # Sander Venema <sander.venema@gmail.com> version 20080819 use strict; use Getopt::Long; use Pod::Usage; use Data::Dumper; use Date::ISO; use POSIX qw(strftime); # set some defaults my $verbose = 0; my $date = strftime("%Y%m%d", localtime); # fetch options Getopt::Long::Configure(qw(no_ignore_case bundling)); GetOptions( 'h|help' => sub { pod2usage({-verbose => 1, -input => \*DAT +A}); exit; }, 'H|man' => sub { pod2usage({-verbose => 2, -input => \* +DATA}); exit; }, 'v|verbose' => \$verbose, 'd|date=i' => \$date, ) or pod2usage(2); # convert date string to Date::ISO object and calculate the # year, week and number of the day (starting with Monday) my $iso = Date::ISO->new(iso => $date); my ($year, $week, $week_day) = ($iso->year, $iso->iso_week, $iso->iso_ +week_day); # print everything, depending on level of $verbose print "$year-W$week-$week_day\n" if $verbose; print "$week\n" if !$verbose; __DATA__ =head1 NAME calcweek.pl - Calculate the week number from any given date =head1 SYNOPSIS calcweek.pl [-h] [-H] [-v] [-d yyyymmdd] =head1 DESCRIPTION This is a small Perl script to calculate the number of the week from a +ny given date, (given in the ISO 8601 format), or uses today's date if no date is spe +cified. It was written just to scratch an itch I had in the past, when I frequently n +eeded to know the number of the week for planning purposes. The program returns the number of the week it is, and if verbose is tu +rned on, it will print the year, weeknumber, and day of the week in ISO 8601 forma +t (YYYY-Www-D). When verbose is turned off, it will only output the number of the week +. The following options are available: -h --help Display this help -H --man Display detailed help (manpage) -v --verbose Turn more verbose messages on -d --date <yyyymmdd> Set the date to calculate (default: tod +ay) =head1 DEPENDENCIES Date::ISO, POSIX, Getopt::Long, Pod::Usage, Data::Dumper =head1 SEE ALSO For more information about ISO 8601: http://www.iso.org/iso/date_and_time_format =head1 BUGS Lots. Probably. Any help on how to improve it is appreciated. :-) =head1 AUTHOR Sander Venema

In reply to calcweek by sv87

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found