Skip to content
Snippets Groups Projects
Select Git revision
  • ee4a94ed752eabb05cc54464b5aa62d7fc42c0aa
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

document.php

Blame
  • Month.php 2.32 KiB
    <?php
    
    class Nmc_Month {
    
        protected $_year;
        protected $_month;
    
        public function __construct($year, $month)
        {
            $this->_year = $year;
            $this->_month = $month;
        }
    
        public function daysInMonth()
        {
            $day = 31;
            for(; !checkdate($this->_month, $day, $this->_year); $day--);
            return $day;
        }
    
        public function firstWeekdayOfMonth()
        {
            $time = strtotime($this->_year . '-' . $this->_month . '-01');
            $weekday = date("w", $time);
            return $weekday;
        }
    
        public function lastWeekdayOfMonth()
        {
            $day = $this->daysInMonth();
    
            $time = strtotime($this->_year . '-' . $this->_month . '-' . $day);
            $weekday = date("w", $time);
            return $weekday;
        }
    
        public function weeksInMonth()
        {
            return ceil(($this->firstWeekdayOfMonth() + $this->daysInMonth()) / 7);
        }
    
        public function getPreviousMonth()
        {
            if($this->_month == 1) return new Month($this->_year - 1, 12);
            return new Nmc_Month($this->_year, $this->_month - 1);
        }
    
        public function getNextMonth()
        {
            if($this->_month == 12) return new Month($this->_year + 1, 1);
            return new Month($this->_year, $this->_month + 1);
        }
    
        public function getWeekOfMonth($week)
        {
            $days = array();
    
            $firstWeekday = $this->firstWeekdayOfMonth();
            $firstDay = $week * 7 - $firstWeekday + 1;
    
            if($firstDay < 1) {
                $firstDay = $this->getPreviousMonth()->daysInMonth() + $firstDay;
                for($i = 0; $i < 7; $i++) {
                    if($i < $firstWeekday) {
                        $days[] = array($firstDay + $i, 'previous');
                    } else {
                        $days[] = array($i - $firstWeekday + 1, 'current');
                    }
                }
            } else if($firstDay + 6 > $this->daysInMonth()) {
                $lastWeekday = $this->lastWeekdayOfMonth();
                for($i = 0; $i < 7; $i++) {
                    if($i <= $lastWeekday) {
                        $days[] = array($i + $firstDay, 'current');
                    } else {
                        $days[] = array($i - $lastWeekday, 'next');
                    }
                }
            } else {
                for($i = 0; $i < 7; $i++) {
                    $days[] = array($i + $firstDay, 'current');
                }
            }
    
            return $days;
        }
    }