function testMonthModule() { $myMonth = new Month("13-10-foodbank", "published"); $this->assertTrue($myMonth->get_id() == "13-10-foodbank"); $this->assertEqual($myMonth->get_group(), "foodbank"); $this->assertTrue($myMonth->get_status() == "published"); $this->assertTrue($myMonth->get_end_of_month_timestamp() == mktime(0, 0, 0, 10, 31, 2013)); echo "testMonth complete"; }
function getall_months() { connect(); $query = "SELECT * FROM dbMonthsORDER BY end_of_month_timestamp"; $result = mysql_query($query); $theMonths = []; while ($result_row = mysql_fetch_assoc($result)) { $theMonth = new Month($result_row['id'], $result_row['group'], $result_row['status']); $theMonth->set_end_of_month_timestamp($result_row['end_of_month_timestamp']); $theMonths[] = $theMonth; } return $theMonths; }
/** * 月の情報を返す * * @param string $baseYear 開始年 * @param string $targetMonth 対象の月 * @param boolean $beginMonday 基準を月曜日にするか * @param int $loop 何年間分欲しいか * * @return array */ function getMonth($baseYear, $targetMonth, $beginMonday = false, $loop = 20) { $ret = array(); for ($i = 0; $i <= $loop; $i++) { $month = Month::forge($baseYear + $i . $targetMonth, $beginMonday)->prepare()->calc(); $weekCnt = $month->getWeeksCount(); $weeks = $month->getWeeks(); $key = $baseYear + $i . '/' . $targetMonth; $ret[$key]['days'] = $weeks[$weekCnt]->getDays(); $ret[$key]['includeNextYear'] = $weeks[$weekCnt]->includedNextMonthDayCnt() > 3; $ret[$key]['weekCnt'] = $weekCnt; } return $ret; }
/** * Test Converting Methods * */ function test_converting() { // Converting $timespan = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10)); // asDate() $temp = $timespan->asDate(); $this->assertTrue($temp->isEqualTo(Date::withYearMonthDay(2005, 5, 4))); // asDateAndTime() $temp = $timespan->asDateAndTime(); $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 00, 00, 00))); // asDuration() $temp = $timespan->asDuration(); $this->assertTrue($temp->isEqualTo(Duration::withDays(365))); // asMonth() $temp = $timespan->asMonth(); $this->assertTrue($temp->isEqualTo(Month::withMonthYear(5, 2005))); // asTime() $temp = $timespan->asTime(); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0); $this->assertTrue($temp->isEqualTo($dateAndTime->asTime())); // asTimeStamp() $temp = $timespan->asTimeStamp(); $this->assertTrue($temp->isEqualTo(TimeStamp::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0))); // asWeek() $temp = $timespan->asWeek(); $this->assertTrue($temp->isEqualTo(Week::starting(Date::withYearMonthDay(2005, 5, 1)))); // asYear() $temp = $timespan->asYear(); $this->assertTrue($temp->isEqualTo(Year::starting(Date::withYearMonthDay(2005, 5, 4)))); // to() $temp = $timespan->to(Date::withYearMonthDay(2005, 10, 1)); $comparison = Timespan::startingEnding(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0), Date::withYearMonthDay(2005, 10, 1)); $this->assertTrue($temp->isEqualTo($comparison)); }
function newMonth($id) { $days = array(1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat"); $fpdays = array(1 => "Mon", 2 => "Wed930", 3 => "Wed1100", 4 => "Thu", 5 => "Fri", 6 => "Sat"); if (substr($id, 6) == "foodpantry") { $thisdays = $fpdays; } else { $thisdays = $days; } // We switched new months to default to published, because otherwise they won't be available for viewing. // We're unsure if this was the right move to make. $new_month = new Month($id, "unpublished"); $new_crews = $new_month->get_crews(); $dom = 1; // day of the month, 1, 2, ..., 31 $week_no = 1; // master schedule week number $firstdow = $dow = date("N", mktime(0, 0, 0, substr($id, 3, 2), "01", substr($id, 0, 2))); // day of week, 1 = Monday if (substr($id, 6) == "foodpantry" && $firstdow == 3) { $firstdow = $dow = 2; } $newbies = array(); foreach ($new_crews as $new_crew) { if ($dom == sizeof($new_crews) && substr($id, 6) == "foodpantry" && $dow == 2) { break; } $id1 = substr($id, 6) . $thisdays[$dow] . $week_no; $schedule_entry = retrieve_dbMasterSchedule($id1); if ($schedule_entry && $schedule_entry->get_slots() > 0) { if ($dom < 10) { $dd = "-0" . $dom; } else { $dd = "-" . $dom; } $person_ids = $schedule_entry->get_persons(); $crew_names = array(); foreach ($person_ids as $person_id) { if ($person_id == "") { continue; } $p = retrieve_person($person_id); if ($p) { $crew_names[] = $person_id . "+" . $p->get_first_name() . "+" . $p->get_last_name() . "+(" . implode(' ', $p->get_role()) . ")"; } else { $crew_names[] = $person_id . "+++"; } } $newbie = new Crew(substr($id, 0, 5) . $dd, substr($id, 6), $schedule_entry->get_slots(), $crew_names, "", ""); $new_month->set_crew($dom, $newbie->get_id()); $newbies[] = $newbie; } if ($dow == 7) { $dow = 1; } else { $dow++; } if ($dow == $firstdow) { $week_no++; } $dom++; } update_dbMonths($new_month); foreach ($newbies as $newbie) { update_dbCrews($newbie); } return $new_month; }
/** * (PHP 5 >= 5.1.0)<br/> * Return the key of the current element * @link http://php.net/manual/en/iterator.key.php * @return scalar scalar on success, integer * 0 on failure. */ public function key() { return $this->current->getBegin()->format('m'); }
/** * Set the month * * @param mixed $anIntOrString * @return void * @access private * @since 5/23/05 */ function setMonth($anIntOrString) { if (!$anIntOrString) { $this->month = NULL; } else { if (is_numeric($anIntOrString)) { $this->month = intval($anIntOrString); } else { $this->month = Month::indexOfMonth($anIntOrString); } } }
/** * Create a new instance. aMonth is an Integer or a String * * @param string $anIntOrStrMonth * @return object Duration * @access public * @since 5/13/05 * @static */ static function withMonth($anIntOrStrMonth) { $currentYear = Year::current(); $month = Month::withMonthYear($anIntOrStrMonth, $currentYear->startYear()); $obj = $month->duration(); return $obj; }
/** * Test converting */ function test_converting() { $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5)); // asDate() $temp = $dateAndTime->asDate(); $this->assertTrue($temp->isEqualTo(Date::withYearMonthDay(2005, 6, 4))); // asDuration() $temp = $dateAndTime->asDuration(); $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510))); // asDateAndTime() $temp = $dateAndTime->asDateAndTime(); $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5)))); // asLocal() $startDuration = Duration::withHours(-5); $localOffset = DateAndTime::localOffset(); $difference = $localOffset->minus($startDuration); $temp = $dateAndTime->asLocal(); $local = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15 + $difference->hours(), 25, 10, $localOffset); $this->assertTrue($temp->isEqualTo($local)); // asMonth() $temp = $dateAndTime->asMonth(); $this->assertTrue($temp->isEqualTo(Month::withMonthYear(6, 2005))); // asSeconds() $localOffset = DateAndTime::localOffset(); $this->assertEqual($dateAndTime->asSeconds(), 3295369510 + $localOffset->asSeconds()); // asTime() $temp = $dateAndTime->asTime(); $this->assertTrue($temp->isEqualTo(Time::withHourMinuteSecond(15, 25, 10))); $this->assertTrue($temp->isEqualTo(Time::withSeconds(55510))); // asTimeStamp() $temp = $dateAndTime->asTimeStamp(); $this->assertTrue($temp->isEqualTo(TimeStamp::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5)))); // asUTC() $temp = $dateAndTime->asUTC(); $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 20, 25, 10, Duration::withHours(0)))); // asWeek() $temp = $dateAndTime->asWeek(); $this->assertTrue($temp->isEqualTo(Week::starting($dateAndTime))); // asYear() $temp = $dateAndTime->asYear(); $this->assertTrue($temp->isEqualTo(Year::starting($dateAndTime))); // midnight(); $temp = $dateAndTime->atMidnight(); $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 6, 4, 0, 0, 0))); // middleOf() $dat = DateAndTime::withYearDay(2005, 100); $timespan = $dat->middleOf(Duration::withDays(100)); $start = $timespan->start(); $duration = $timespan->duration(); $end = $timespan->end(); $this->assertEqual($start->dayOfYear(), 50); $this->assertTrue($start->isEqualTo(DateAndTime::withYearDay(2005, 50))); $this->assertEqual($duration->days(), 100); $this->assertEqual($end->dayOfYear(), 149); // to() $datA = DateAndTime::withYearDay(2005, 125); $datB = DateAndTime::withYearDay(2006, 125); $timespan = $datA->to($datB); $this->assertEqual($timespan->startYear(), 2005); $this->assertEqual($timespan->dayOfYear(), 125); $duration = $timespan->duration(); $this->assertTrue($duration->isEqualTo(Duration::withDays(365))); $end = $timespan->end(); $this->assertEqual($end->julianDayNumber(), 2453860); $this->assertEqual($end->julianDayNumber() - $datA->julianDayNumber(), 364); $this->assertEqual($end->year(), 2006); $this->assertEqual($end->dayOfYear(), 124); $this->assertTrue($end->isEqualTo(DateAndTime::withYearDayHourMinuteSecond(2006, 124, 23, 59, 59))); // withOffset() $temp = $dateAndTime->withOffset(Duration::withHours(-7)); $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-7)))); }
/** * Print a description of the receiver on aStream using the format * denoted the argument, formatArray: * * array(item, item, item, sep, monthfmt, yearfmt, twoDigits) * * items: 1=day 2=month 3=year will appear in the order given, * * separated by sep which is eaither an ascii code or character. * * monthFmt: 1=09 2=Sep 3=September * * yearFmt: 1=1996 2=96 * * digits: (missing or)1=9 2=09. * * See the examples in printOn: and mmddyy * * @param array $formatArray * @return string * @access public * @since 5/20/05 */ function printableStringWithFormat($formatArray) { $result = ''; $twoDigits = count($formatArray) > 6 && $formatArray[6] > 1; $monthFormat = $formatArray[4]; $yearFormat = $formatArray[5]; $separator = $formatArray[3]; for ($i = 0; $i < 3; $i++) { $element = $formatArray[$i]; switch ($element) { case 1: if ($twoDigits) { $result .= str_pad($this->dayOfMonth(), 2, '0', STR_PAD_LEFT); } else { $result .= $this->dayOfMonth(); } break; case 2: if ($monthFormat == 1) { if ($twoDigits) { $result .= str_pad($this->startMonth(), 2, '0', STR_PAD_LEFT); } else { $result .= $this->startMonth(); } } else { if ($monthFormat == 2) { $result .= substr(Month::nameOfMonth($this->startMonth()), 0, 3); } else { if ($monthFormat == 3) { $result .= Month::nameOfMonth($this->startMonth()); } } } break; case 3: if ($yearFormat == 2) { $result .= str_pad($this->startYear() % 100, 2, '0', STR_PAD_LEFT); } else { $result .= $this->startYear(); } } if ($i < 2 && $separator) { $result .= $separator; } } return $result; }
if (!isset($_GET['y'])) { $_GET['y'] = date('Y'); } if (!isset($_GET['m'])) { $_GET['m'] = date('m'); } if (!isset($_GET['d'])) { $_GET['d'] = date('d'); } if ($loggedin_user->hasRight('admin') && isset($_REQUEST['user_id'])) { $user_id = $_REQUEST['user_id']; } else { $user_id = $loggedin_user->id; } // Instantiate the Month class $month = new Month($_GET['y'], $_GET['m'], "Sunday"); // Get the details of the months as timestamps $last = $month->lastMonth(true); $next = $month->nextMonth(true); $thisMonth = $month->thisMonth(true); // Get the task data $task = new SI_Task(); $tasks = $task->getCalendarTasks($user_id, $thisMonth, $next, 'day'); if ($tasks === FALSE) { $error_msg .= "Could not retrieve Tasks!\n"; debug_message($task->getLastError()); } // Get the activity data $ta = new SI_TaskActivity(); $activities = $ta->getCalendarActivities($user_id, $thisMonth, $next, 'day'); if ($activities === FALSE) {
/** * Test converting methods * */ function test_converting() { $time = Time::withHourMinuteSecond(15, 25, 10); // asDate () $temp = $time->asDate(); $this->assertTrue($temp->isEqualTo(Date::today())); $this->assertEqual(strtolower(get_class($temp)), 'date'); // asDateAndTime () $temp = $time->asDateAndTime(); $comparison = DateAndTime::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'dateandtime'); // asDuration () $temp = $time->asDuration(); $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510))); $this->assertEqual(strtolower(get_class($temp)), 'duration'); // asMonth () $temp = $time->asMonth(); $this->assertTrue($temp->isEqualTo(Month::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'month'); // asSeconds () $this->assertEqual($time->asSeconds(), 55510); // asTime () $temp = $time->asTime(); $this->assertTrue($temp->isEqualTo($time)); $this->assertEqual(strtolower(get_class($temp)), 'time'); // asTimeStamp () $temp = $time->asTimeStamp(); $comparison = TimeStamp::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'timestamp'); // asWeek () $temp = $time->asWeek(); $this->assertTrue($temp->isEqualTo(Week::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'week'); // asYear () $temp = $time->asYear(); $this->assertTrue($temp->isEqualTo(Year::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'year'); // to () $today = DateAndTime::today(); $tomorrow = DateAndTime::tomorrow(); $result = $time->to($tomorrow); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 34, 50)))); $result = $time->to(Time::withHourMinuteSecond(23, 25, 10)); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 0, 0)))); }
/** * Get the distance between this and the given month. * * @param Month $month * * @return int Number of months */ public function getDistance(Month $month) { $yd = $this->getYear() - $month->getYear(); $md = $this->getMonth() - $month->getMonth(); return ($yd * 12 + $md) * -1; }
/** * */ public function testGetDistance() { $month1 = new Month(new \DateTime('1987-06-18')); $month2 = new Month(new \DateTime('2013-03-08')); $this->assertEquals(309, $month1->getDistance($month2)); $this->assertEquals(-309, $month2->getDistance($month1)); }
/** * Print the dateRange form * * @param object DateAndTime $startDate * @param object DateAndTime $endDate * @return void * @access public * @since 3/8/06 */ function printDateRangeForm($startDate, $endDate) { $min = $this->minDate(); $max = DateAndTime::tomorrow(); $harmoni = Harmoni::instance(); print "\n<form action='"; $harmoni->request->forget('startYear'); $harmoni->request->forget('startMonth'); $harmoni->request->forget('startDay'); $harmoni->request->forget('startHour'); $harmoni->request->forget('endYear'); $harmoni->request->forget('endMonth'); $harmoni->request->forget('endDay'); $harmoni->request->forget('endHour'); print $harmoni->request->quickURL('logs', 'browse'); $harmoni->request->passthrough('log', 'priority', 'startYear', 'startMonth', 'startDay', 'startHour', 'endYear', 'endMonth', 'endDay', 'endHour', 'agent_id', 'node_id', 'category'); print "' method='post'>"; print "\n\t<select name='" . RequestContext::name("startMonth") . "'>"; $month = 1; while ($month <= 12) { print "\n\t\t<option value='" . $month . "'"; print $month == $startDate->month() ? " selected='selected'" : ""; print ">" . Month::nameOfMonth($month) . "</option>"; $month++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("startDay") . "'>"; $day = 1; while ($day <= 31) { print "\n\t\t<option value='" . $day . "'"; print $day == $startDate->dayOfMonth() ? " selected='selected'" : ""; print ">" . $day . "</option>"; $day++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("startYear") . "'>"; $year = $max->year(); $minYear = $min->year(); while ($year >= $minYear) { print "\n\t\t<option value='" . $year . "'"; print $year == $startDate->year() ? " selected='selected'" : ""; print ">{$year}</option>"; $year--; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("startHour") . "'>"; $hour = 0; while ($hour <= 23) { print "\n\t\t<option value='" . $hour . "'"; print $hour == $startDate->hour() ? " selected='selected'" : ""; print ">" . sprintf("%02d", $hour) . ":00</option>"; $hour++; } print "\n\t</select>"; print "\n\t<strong> to: </strong>"; print "\n\t<select name='" . RequestContext::name("endMonth") . "'>"; $month = 1; while ($month <= 12) { print "\n\t\t<option value='" . $month . "'"; print $month == $endDate->month() ? " selected='selected'" : ""; print ">" . Month::nameOfMonth($month) . "</option>"; $month++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("endDay") . "'>"; $day = 1; while ($day <= 31) { print "\n\t\t<option value='" . $day . "'"; print $day == $endDate->dayOfMonth() ? " selected='selected'" : ""; print ">" . $day . "</option>"; $day++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("endYear") . "'>"; $year = $max->year(); $minYear = $min->year(); while ($year >= $minYear) { print "\n\t\t<option value='" . $year . "'"; print $year == $endDate->year() ? " selected='selected'" : ""; print ">{$year}</option>"; $year--; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("endHour") . "'>"; $hour = 0; while ($hour <= 23) { print "\n\t\t<option value='" . $hour . "'"; print $hour == $endDate->hour() ? " selected='selected'" : ""; print ">" . sprintf("%02d", $hour) . ":00</option>"; $hour++; } print "\n\t</select>"; print "\n\t<input type='submit' value='" . _("Set Range") . "'/>"; print "\n\t<a href='"; print $harmoni->request->quickURL('logs', 'browse', array('startYear' => $min->year(), 'startMonth' => $min->month(), 'startDay' => $min->dayOfMonth(), 'startHour' => $min->hour(), 'endYear' => $max->year(), 'endMonth' => $max->month(), 'endDay' => $max->dayOfMonth(), 'endHour' => $max->hour())); print "'>"; print "\n\t\t<input type='button' value='" . _("Clear") . "' />"; print "</a>"; print "\n</form>"; }
/** * Create a new object starting now, with a given duration. * Override - as each month has a defined duration * * @param object DateAndTime $aDateAndTime * @param object Duration $aDuration * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object Month * @access public * @since 5/5/05 * @static */ static function startingDuration($aDateAndTime, $aDuration, $class = 'Month') { // Validate our passed class name. if (!(strtolower($class) == strtolower('Month') || is_subclass_of(new $class(), 'Month'))) { die("Class, '{$class}', is not a subclass of 'Month'."); } $start = $aDateAndTime->asDateAndTime(); $adjusted = DateAndTime::withYearMonthDay($start->year(), $start->month(), 1); $days = Month::daysInMonthForYear($adjusted->month(), $adjusted->year()); $month = new $class(); $month->setStart($adjusted); $month->setDuration(Duration::withDays($days)); return $month; }
/** * Answer the month that represents this date's month * * @return object Month * @access public * @since 5/5/05 */ function asMonth() { $obj = Month::starting($this); return $obj; }