B
Bart Van der Donck
Hello,
I have an array of dates. I don't know the number of dates it contains,
nor where they start or end. But I know they are following each other
(no missing dates in between), e.g.
my @days = ("20051230","20051231",
"20060101","20060102","20060103");
Then I have a hash that holds price periods valid for named weekdays,
e.g.
my %prices = ( "20051010-20051031|SUN-FRI" => 12.45,
"20051010-20051031|FRI-SUN" => 18.45,
"20051101-20060115|TUE-THU" => 11.24,
"20051101-20060115|THU-MON" => 12.11
);
Meaning, eg the first element: during 20051010-20051031, the price is
12.45 from Sunday-Friday. The elements of %prices are always in this
fixed format.
The weekday notation excludes the last day, e.g. FRI-SUN is valid for
FRI and SAT, but not for SUN. If a price/weekday combination is not in
the hash, it means they are not available and perl should return an
error 'no price available'. From the example above: no price available
on MON during 20051101-20060115. Also, no price available for Aug 10,
2006 in the example above.
All dates are in YYYYMMDD format, weekdays are MON TUE WED THU FRI SAT
SUN.
Background: @days are the days that a user wants to book a hotel room.
%prices are my delivered price periods.
Each date in @array is the startdate of an overnight, e.g. 20051230
means "the night that starts on Dec 30, 2005 and ends on Dec 31, 2005".
The price is the room price for 1 night.
Each date pair in %prices is the start date and the end date, including
the last day. From the example above: the price for an overnight from
Oct 31, 2005 to Nov 01, 2006 (1 night) is 12.45 (Oct 31, 2005 is on a
Monday).
I moved earth to heaven trying to get a new simple hash like this:
%newpriceformat = ("20050529" => 40.42,
"20050530" => 40.42,
"20050531" => 40.42,
"20050601" => 38.62,
"20050602" => 38.62
);
Basically, I think the problem can be narrowed down to a reformatting
of %prices into %newpriceformat. Once that far, it's not that hard to
link this to @days. But I couldn't get it working with Date::Calc,
Date::Manip, assign numbers to days... but I believe it should be
somewhere in that direction (I wouldn't know where else).
Thanks,
I have an array of dates. I don't know the number of dates it contains,
nor where they start or end. But I know they are following each other
(no missing dates in between), e.g.
my @days = ("20051230","20051231",
"20060101","20060102","20060103");
Then I have a hash that holds price periods valid for named weekdays,
e.g.
my %prices = ( "20051010-20051031|SUN-FRI" => 12.45,
"20051010-20051031|FRI-SUN" => 18.45,
"20051101-20060115|TUE-THU" => 11.24,
"20051101-20060115|THU-MON" => 12.11
);
Meaning, eg the first element: during 20051010-20051031, the price is
12.45 from Sunday-Friday. The elements of %prices are always in this
fixed format.
The weekday notation excludes the last day, e.g. FRI-SUN is valid for
FRI and SAT, but not for SUN. If a price/weekday combination is not in
the hash, it means they are not available and perl should return an
error 'no price available'. From the example above: no price available
on MON during 20051101-20060115. Also, no price available for Aug 10,
2006 in the example above.
All dates are in YYYYMMDD format, weekdays are MON TUE WED THU FRI SAT
SUN.
Background: @days are the days that a user wants to book a hotel room.
%prices are my delivered price periods.
Each date in @array is the startdate of an overnight, e.g. 20051230
means "the night that starts on Dec 30, 2005 and ends on Dec 31, 2005".
The price is the room price for 1 night.
Each date pair in %prices is the start date and the end date, including
the last day. From the example above: the price for an overnight from
Oct 31, 2005 to Nov 01, 2006 (1 night) is 12.45 (Oct 31, 2005 is on a
Monday).
I moved earth to heaven trying to get a new simple hash like this:
%newpriceformat = ("20050529" => 40.42,
"20050530" => 40.42,
"20050531" => 40.42,
"20050601" => 38.62,
"20050602" => 38.62
);
Basically, I think the problem can be narrowed down to a reformatting
of %prices into %newpriceformat. Once that far, it's not that hard to
link this to @days. But I couldn't get it working with Date::Calc,
Date::Manip, assign numbers to days... but I believe it should be
somewhere in that direction (I wouldn't know where else).
Thanks,