Esempio n. 1
0
 /**
  * Transform a last period to a 2 dates
  *
  */
 public function period2dates($when)
 {
     global $prefs;
     $tikilib = TikiLib::lib('tiki');
     $now = $tikilib->now;
     $sec = TikiLib::date_format("%s", $now);
     $min = TikiLib::date_format("%i", $now);
     $hour = TikiLib::date_format("%H", $now);
     $day = TikiLib::date_format("%d", $now);
     $month = TikiLib::date_format("%m", $now);
     $year = TikiLib::date_format("%Y", $now);
     switch ($when) {
         case 'lasthour':
             $begin = $now - 60 * 60;
             break;
         case 'day':
             $begin = TikiLib::make_time(0, 0, 0, $month, $day, $year);
             break;
         case 'lastday':
             $begin = Tikilib::make_time($hour - 24, $min, $sec, $month, $day, $year);
             break;
         case 'week':
             $iweek = TikiLib::date_format("%w", $now);
             // 0 for Sunday...
             $calendarlib = TikiLib::lib('calendar');
             $firstDayofWeek = $calendarlib->firstDayofWeek();
             $iweek -= $firstDayofWeek;
             if ($iweek < 0) {
                 $iweek += 7;
             }
             $begin = TikiLib::make_time(0, 0, 0, $month, $day - $iweek, $year);
             break;
         case 'lastweek':
             $begin = Tikilib::make_time($hour, $min, $sec, $month, $day - 7, $year);
             break;
         case 'month':
             $begin = TikiLib::make_time(0, 0, 0, $month, 1, $year);
             break;
         case 'lastmonth':
             $begin = TikiLib::make_time($hour, $min, $sec, $month - 1, $day, $year);
             break;
         case 'year':
             $begin = TikiLib::make_time(0, 0, 0, 1, 1, $year);
             break;
         case 'lastyear':
             $begin = TikiLib::make_time($hour, $min, $sec, $month, $day, $year - 1);
             break;
         default:
             $begin = $now;
             break;
     }
     return array((int) $begin, (int) $now);
 }
Esempio n. 2
0
 /**
  * @param $focus
  * @param string $view
  * @return array
  */
 function focusNext($focus, $view = 'month')
 {
     $nbMonths = array('day' => 0, 'week' => 0, 'month' => 1, 'bimester' => 2, 'trimester' => 3, 'quarter' => 4, 'semester' => 6, 'year' => 12);
     $nbDays = array('day' => 1, 'week' => 7, 'month' => 0, 'bimester' => 0, 'trimester' => 0, 'quarter' => 0, 'semester' => 0, 'year' => 0);
     $next = $focus;
     $next['day'] += $nbDays[$view];
     if ($next['month'] + $nbMonths[$view] > 12) {
         $next['month'] = ($next['month'] - 1 + $nbMonths[$view]) % 12 + 1;
         $next['year'] += 1;
     } else {
         $next['month'] += $nbMonths[$view];
     }
     $next['daysInMonth'] = Date_Calc::daysInMonth($next['month'], $next['year']);
     if ($next['day'] > $next['daysInMonth']) {
         $next['day'] = $next['daysInMonth'];
     }
     $next['date'] = Tikilib::make_time(0, 0, 0, $next['month'], $next['day'], $next['year']);
     $next = $this->infoDate($next['date']);
     // get back real day, month, year
     return $next;
 }
Esempio n. 3
0
 /**
  * Transform a last period to a 2 dates 
  *
  */
 function period2dates($when)
 {
     global $tikilib, $prefs;
     $now = $tikilib->now;
     $sec = TikiLib::date_format("%s", $now);
     $min = TikiLib::date_format("%i", $now);
     $hour = TikiLib::date_format("%H", $now);
     $day = TikiLib::date_format("%d", $now);
     $month = TikiLib::date_format("%m", $now);
     $year = TikiLib::date_format("%Y", $now);
     switch ($when) {
         case 'lasthour':
             $begin = $now - 60 * 60;
             break;
         case 'day':
             $begin = TikiLib::make_time(0, 0, 0, $month, $day, $year);
             break;
         case 'lastday':
             $begin = Tikilib::make_time($hour - 24, $min, $sec, $month, $day, $year);
             break;
         case 'week':
             $iweek = TikiLib::date_format("%w", $now);
             // 0 for Sunday...
             if ($prefs['calendar_firstDayofWeek'] == 'user') {
                 $firstDayofWeek = (int) tra('First day of week: Sunday (its ID is 0) - translators you need to localize this string!');
                 if ($firstDayofWeek < 1 || $firstDayofWeek > 6) {
                     $firstDayofWeek = 0;
                 }
             } else {
                 $firstDayofWeek = $prefs['calendar_firstDayofWeek'];
             }
             $iweek -= $firstDayofWeek;
             if ($iweek < 0) {
                 $iweek += 7;
             }
             $begin = TikiLib::make_time(0, 0, 0, $month, $day - $iweek, $year);
             break;
         case 'lastweek':
             $begin = Tikilib::make_time($hour, $min, $sec, $month, $day - 7, $year);
             break;
         case 'month':
             $begin = TikiLib::make_time(0, 0, 0, $month, 1, $year);
             break;
         case 'lastmonth':
             $begin = TikiLib::make_time($hour, $min, $sec, $month - 1, $day, $year);
             break;
         case 'year':
             $begin = TikiLib::make_time(0, 0, 0, 1, 1, $year);
             break;
         case 'lastyear':
             $begin = TikiLib::make_time($hour, $min, $sec, $month, $day, $year - 1);
             break;
         default:
             $begin = $now;
             break;
     }
     return array((int) $begin, (int) $now);
 }