Veritas-bu

Re: [Veritas-bu] Need date calculation utility

2007-12-20 17:47:11
Subject: Re: [Veritas-bu] Need date calculation utility
From: A Darren Dunham <ddunham AT taos DOT com>
To: veritas-bu AT mailman.eng.auburn DOT edu
Date: Thu, 20 Dec 2007 22:27:35 +0000
On Thu, Dec 20, 2007 at 11:56:44AM -0800, Conner, Neil wrote:
> I recently switched my offsite schedule to an every-other Tuesday
> schedule and I'm having difficulty calculating a valid return date for
> that scenario.

Is this frequency based?  Is it possible that the schedule could slip by
a week at some point in the future so that you're on the alternate set
of days?


> How do I know if any given Tuesday in the future falls on a service
> date or not?  I'm running Solaris and I have the Date-Calc package by
> Steffen Beyer, but I haven't found an example of how to solve this
> particular problem and I haven't learned perl well enough yet to
> figure it out on my own - has anybody solved a problem like this?

There's lots of ways.  You could ask for every Tuesday in the future and
then just throw away half of them.

You could give it a start date and then just add 14 days to find future
ones.

Or for your specific question (is a given day in the schedule), you
could subtract the difference in days and find out if it's a multiple of
14.

Here's a sample using Date::Calc :

#!/usr/bin/perl
use strict;
use warnings;
use Date::Calc;

my @start_date = (2007,12,20);
my @date = @start_date;
printf "Start date: %4u-%02u-%02u\n", @date;

my $iterations = 10;
print "The next $iterations 2 week date:\n";
for (1 .. $iterations)
{
    @date = Date::Calc::Add_Delta_Days(@date, 14);
    printf "Iteration %u: %4u-%02u-%02u\n", $_, @date;
}

print "\nDoes a given date fall on the 2 week schedule or not?\n";
foreach my $date_ref ([2009,6,17], [2009,6,18])
{
  @date = @{$date_ref};
  my $mod_difference = Date::Calc::Delta_Days(@start_date, @date) % 14;
  printf "Date %4u-%02u-%02u has a modular difference of %u. ",
        (@date, $mod_difference);
  print $mod_difference ? "not on schedule.\n" : "on schedule.\n";
}       

-- 
Darren Dunham                                           ddunham AT taos DOT com
Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >
_______________________________________________
Veritas-bu maillist  -  Veritas-bu AT mailman.eng.auburn DOT edu
http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu