Curses-UI
view release on metacpan or search on metacpan
lib/Curses/UI/Calendar.pm view on Meta::CPAN
my $year = shift;
my $month = shift;
if($month == 2 and is_leap_year($year)) {
return 29;
} else {
return $days_in_month[$month];
}
}
sub is_leap_year($;)
{
my $year = shift;
if (is_julian($year,1)) {
return 1 if $year % 4 == 0;
} else {
return 1 if ($year % 4 == 0 and $year % 100 != 0)
or $year % 400 == 0;
}
return 0;
}
sub build_month ($$;)
{
my $year = shift;
my $month = shift;
my $first_weekday = day_of_week($year, $month, 1);
my $number_of_days = days_in_month($year, $month);
if ($year == 1752 and $month == 9) {
$number_of_days = 19;
}
my @month = ();
for (1..$first_weekday) {
push @month, undef;
}
my $realday = 1;
for( my $day = 1; $day <= $number_of_days; $day++ )
{
push @month, $realday;
if ($year == 1752 and $month == 9 and $realday == 2) {
$realday = 13;
}
$realday++;
}
return @month;
}
1;
=pod
=head1 NAME
Curses::UI::Calendar - Create and manipulate calendar widgets
=head1 CLASS HIERARCHY
Curses::UI::Widget
|
+----Curses::UI::Calendar
=head1 SYNOPSIS
use Curses::UI;
my $cui = new Curses::UI;
my $win = $cui->add('window_id', 'Window');
my $calendar = $win->add(
'mycalendar', 'Calendar',
-date => '2002-1-14'
);
$calendar->focus();
my $date = $calendar->get();
=head1 DESCRIPTION
Curses::UI::Calendar is a widget that can be used to create
a calendar in which the user can select a date. The calendar
widget looks like this:
+----------------------+
| mmm dd yyyy |
+----------------------+
| su mo tu we th fr sa |
| |
| 01 02 03 04 05 |
| 06 07 08 09 10 11 12 |
| 13 14 15 16 17 18 19 |
| 20 21 22 23 24 25 26 |
| 27 28 29 30 31 |
+----------------------+
See exampes/demo-Curses::UI::Calendar in the distribution
for a short demo.
=head1 STANDARD OPTIONS
B<-parent>, B<-x>, B<-y>, B<-width>, B<-height>,
B<-pad>, B<-padleft>, B<-padright>, B<-padtop>, B<-padbottom>,
B<-ipad>, B<-ipadleft>, B<-ipadright>, B<-ipadtop>, B<-ipadbottom>,
B<-title>, B<-titlefullwidth>, B<-titlereverse>, B<-onfocus>,
B<-onblur>
For an explanation of these standard options, see
L<Curses::UI::Widget|Curses::UI::Widget>.
B<Remark>: B<-width> and B<-height> can be set, but this widget
really want to have its content space at a minimum size. If your
B<-width> or B<-height> is not large enough, the widget will
automatically fix its value.
=head1 WIDGET-SPECIFIC OPTIONS
=over 4
=item * B<-date> < DATE >
This option sets the date to start with.
If you do not specify a date, today's
date will be used automatically. The format that
you can use for this date is one of:
* B<YYYY-M-D> (e.g. 2002-1-10 or 2002-01-10)
* B<YYYY/M/D> (e.g. 2002/1/10 or 2002/01/10))
* B<YYYYMMDD> (e.g. 20020110)
* B<D-M-YYYY> (e.g. 10-1-2002 or 10/01/2002)
* B<D/M/YYYY> (e.g. 10/1/2002 or 10/01/2002)
=item * B<-onchange> < CODEREF >
This sets the onChange event handler for the calendar widget.
If a new date is selected, the code in CODEREF will be executed.
It will get the widget reference as its argument.
=item * B<-drawline> < CODEREF >
This option specifies whether or not a line should be drawn under
the calendar.
=back
=head1 METHODS
=over 4
=item * B<new> ( OPTIONS )
=item * B<layout> ( )
=item * B<draw> ( BOOLEAN )
=item * B<focus> ( )
=item * B<onFocus> ( CODEREF )
=item * B<onBlur> ( CODEREF )
=item * B<intellidraw> ( )
These are standard methods. See L<Curses::UI::Widget|Curses::UI::Widget>
for an explanation of these.
=item * B<get> ( )
This method will return the currently selected date in the
format 'YYYY-MM-DD'.
=item * B<setdate> ( DATE, [BOOLEAN] )
Set the selected date of the widget to DATE. See B<-date> above for
the possible formats. The widget will redraw itself, unless BOOLEAN
has a true value.
=item * B<onChange> ( CODEREF )
This method can be used to set the B<-onchange> event handler
(see above) after initialization of the calendar.
=back
=head1 DEFAULT BINDINGS
=over 4
=item * <B<tab>>
Call the 'loose-focus' routine. This will have the menubar
loose its focus and return the value 'LOOSE_FOCUS' to
the calling routine.
=item * <B<enter>>, <B<space>>
Call the 'date-select' routine. This will select the date on
which the cursor is.
=item * <B<cursor-left>>, <B<h>>
Call the 'date-prevday' routine. This will have the date
cursor go back one day.
=item * <B<cursor-right>, <B<l>>
Call the 'date-nextday' routine. This will have the
date cursor go forward one day.
=item * <B<cursor-down>>, <B<j>>
Call the 'date-nextweek' routine. This will have the
date cursor go forward one week.
=item * <B<cursor-up>>, <B<k>>
Call the 'date-prevweek' routine. This will have the
date cursor go back one week.
=item * <B<page-up>>, <B<SHIFT+K>>
Call the 'date-prevmonth' routine. This will have the
date cursor go back one month.
=item * <B<page-down>>, <B<SHIFT+J>>
Call the 'date-nextmonth' routine. This will have the
date cursor go forward one month.
=item * <B<p>>, <B<SHIFT+H>>
Call the 'date-prevyear' routine. This will have the
date cursor go back one year.
=item * <B<n>>, <B<SHIFT+L>>
Call the 'date-nextyear' routine. This will have the
date cursor go forward one year.
( run in 1.060 second using v1.01-cache-2.11-cpan-39bf76dae61 )