Skip to content

Commit

Permalink
Add the ability to set month count of generated calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
darylducharme authored and klimeryk committed Jul 9, 2021
1 parent 4335138 commit 204a375
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Config {
public const HABITS_TITLE = 'habits_title';
public const LOCALE = 'locale';
public const MONTH = 'month';
public const MONTH_COUNT = 'month_count';
public const MONTHS = 'months';
public const WEEK_NAME = 'week_name';
public const WEEK_NUMBER = 'week_number';
Expand Down Expand Up @@ -76,6 +77,9 @@ protected function get_configuration() : array {
// You could then set this to 10 (October) and the calendar
// would then be generated for 12 months starting from October.
self::MONTH => 1,
// The number of months you want this calendar to be for.
// Useful if you want a calendar for the quarter (3) or a 15 month calendar.
self::MONTH_COUNT => 12,
// Title of the Week overview page
self::WEEK_NAME => 'Week',
// A short version of "Week Number" used in the header of the small calendar in upper right corner of the page
Expand Down
4 changes: 2 additions & 2 deletions recalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function generate() {
$month = sprintf( '%02d', (int) $this->config->get( Config::MONTH ) );
$year = (int) $this->config->get( Config::YEAR );
$start = new \DateTimeImmutable( "$year-$month-01" );
$next_year = $year + 1;
$end = new \DateTimeImmutable( "$next_year-$month-01" );
$month_count = (int) $this->config->get( Config::MONTH_COUNT );
$end = $start->modify( "$month_count months" );
$year_overview_generator = new YearOverviewGenerator( $start, $end, $this->config );
$this->add_page();
$this->append_html( $year_overview_generator->generate() );
Expand Down

0 comments on commit 204a375

Please sign in to comment.