View Full Version : getting all dates of a specific month, almost
I am trying to output the header of a calendar with the day (M,T,W,T,F,S,S,), date ( 1 - 31).
I need help with the first part so that in a 30 day month, I can show 1 - 30 instead of 1-31.
sub calendar_header {
my $current_date = strftime("%Y %m %d", localtime);
print qq(
cd=$current_date<br />
);
my $err;
my $date = DateCalc("$current_date","+ 31 days",\$err,0);
print qq( date=$date );
}
This will always show 31 days ahead.
I only have POSIX and date::Manip.
If you can I would be very pleased and able to go to bed.
bazz
FishMonger
06-01-2008, 02:57 AM
my $date = DateCalc($current_date, " + 1 month", \$err, 0);
FishMonger
06-01-2008, 03:01 AM
use HTML::CalendarMonth ??
http://search.cpan.org/~msisk/HTML-CalendarMonth-1.19/lib/HTML/CalendarMonth.pm
Thanks FishMonger.
I think I am running out of ideas. :(
I am trying to output a row of dates as shown belkow, but for each date of a selected month.
M T W T F S S
1 2 3 4 5 6 7.......
[code]
This code seems just wrong. if you can guyide me with a 'workflow' I hope I can work it out from there.
[code]
sub calendar_header {
my $current_date = strftime("%Y %m %d", localtime);
$current_date =~ s/ //g;
my $err;
my $time;
my $date = DateCalc($current_date, " + 1 month", \$err, 1);
( $date , $time ) = ($date =~ /(........)/g); # split the time from the date.
print qq( current_date = $current_date<br /> date=$date );
}
bazz
oesxyl
06-01-2008, 03:22 AM
you can use Calendar from Date : : Calc module
use Date::Calc qw(Calendar);
print Calendar(2008,6);
see the documentation of the module.
regards
FishMonger
06-01-2008, 03:23 AM
Outputting a calender is not real easy, as you're finding out.
I'd highly recommend using the calender module that I linked to instead of rolling your own. If you really want to do you own, then take some time to look over the source code of the module so that you'll have a good base to start.
FishMonger
06-01-2008, 03:30 AM
oesxyl's recommendation would be a good option for a console based app, but not for a web app. It's output could be parsed and made into an html table, but why go through the effort when the other module does it all?
Outputting a calender is not real easy, as you're finding out.
lol. tell me about it!! And it isn't really a calendar because the portions of output which in a calendar would be blank squares, will be squares as determined by the db. i.e., if a room is booked on a set day, the square will be red and if vacant, it will be green. other colours too for other scenarios. (That's if my brain doesn't explode firstly).
I expect to be able to do it because I have been 'at' perl for so long now. Hence my (probably obvious), frustration at times. (frustrated with myself that is).
I'd highly recommend using the calender module that I linked to instead of rolling your own. If you really want to do you own, then take some time to look over the source code of the module so that you'll have a good base to start.
OK, I'll see if I can get it installed and try to rustle up something.
bazz
oesxyl
06-01-2008, 03:38 AM
oesxyl's recommendation would be a good option for a console based app, but not for a web app. It's output could be parsed and made into an html table, but why go through the effort when the other module does it all?
for html:
print '<pre>',Calendar(2008,6),'</pre>';
that's work to display the calendar in a html page, pre or p tag could be styled using css and save a lot of work if bazz don't need links from calendar days to other pages or something else.
regards
FishMonger
06-01-2008, 03:48 AM
Yes, you can use the <pre></pre> tags and style it to a limited degree with css, but not to the level of styling that Bazz is wanting.
...and save a lot of work if bazz don't need links from calendar days to other pages or something else.
groan... I do need links from each day. on vacant days (I'm having them more often lol), the click will go to a booking form. occupied days will show the details of the guest. and other types of day will do other stuff.
bazz
Better day today: I have made good progress and think I am nearly there.
Just need a pointer on whether this code is the best way to achieve it.
table like this
|booking_id | check_in_date (ISO) | check_out_date (ISO) | room_status |
this code is meant to prepare a query, loop though each day of the month, execute the query, compare the month dates with the check_in_date and check_out_date and dependent on that match (or not) it puts the date and the room_status in a hash.
my $days = Days_in_Month($year,$month); # number of days this month
sub show_status {
my $room_status = 'vacant';
my $room_name;
my $room_number;
my %dates_and_status;
my @dates;
my $sth = $bookings_db_connect->prepare ("SELECT
RD.room_number,
RD.room_name,
RB.check_in_date,
RB.check_out_date,
RB.room_status
FROM tbl_rooms_details RD, tbl_rooms_booked RB
WHERE RB.room_id = RD.room_id
AND business_id = ?
")or die "prepare statement failed: $DBI::errstr\n";
foreach my $day_number (1..$days)
{
if (length($day_number) < 2 )
{
$day_number = (join ( "" , ( '0', $day_number)));
}
my $full_iso_date = (join("-",($year, $month, $day_number)));
push (@dates_in_month, $full_iso_date);
}
$sth->execute($business_id);
while ( my $room = $sth->fetchrow_hashref)
{
$room_number = $room->{room_number};
$room_name = $room->{room_name};
$check_in_date = $room->{check_in_date};
$check_out_date = $room->{check_out_date};
$room_status = $room->{room_status};
print qq(
<tr>
<td class='rooms_label'>$room_number $room_name </td>
);
foreach my $date (sort @dates_in_month)
{
if ($date >= $check_in_date && $date < $check_out_date)
{
$dates_and_status{$date} = $room_status;
}
}
}
Please tell me if I am on the right track.
bazz
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.