function testCustomPatterns()
 {
     $dateFormatter = new DateFormat();
     $time = mktime(9, 9, 9, 9, 1, 2004);
     $pattern = "'Hello' EEEE, 'it should be' MMM yyyy HH:mm:ss!!!";
     $wants = 'Hello Wednesday, it should be Sep 2004 09:09:09!!!';
     $this->assertEqual($wants, $dateFormatter->format($time, $pattern));
 }
Exemplo n.º 2
0
 /**
  * Renders the localized version of the date-time value.
  * If the culture is not specified, the default application
  * culture will be used.
  * This method overrides parent's implementation.
  */
 protected function getFormattedDate()
 {
     $value = $this->getValue();
     $defaultText = $this->getDefaultText();
     if (empty($value) && !empty($defaultText)) {
         return $this->getDefaultText();
     }
     $app = $this->getApplication()->getGlobalization();
     //initialized the default class wide formatter
     if (self::$formatter === null) {
         self::$formatter = new DateFormat($app->getCulture());
     }
     $culture = $this->getCulture();
     //return the specific cultural formatted date time
     if (strlen($culture) && $app->getCulture() !== $culture) {
         $formatter = new DateFormat($culture);
         return $formatter->format($value, $this->getPattern(), $this->getCharset());
     }
     //return the application wide culture formatted date time.
     $result = self::$formatter->format($value, $this->getPattern(), $this->getCharset());
     return $result;
 }
Exemplo n.º 3
0
 public function getData()
 {
     if (isset($this->Request['f1'])) {
         $year = $this->Request['f3'];
         $this->employee = new employee($this->Request['f2']);
     } else {
         $year = $this->FilterYear->getSelectedValue();
     }
     $config = $this->employee->getConfig();
     $months = array();
     $app = $this->getApplication()->getGlobalization();
     $nHolidays = 0;
     $totalYearHoursX = 0;
     $nWeekH = 0;
     for ($i = 1; $i <= 12; $i++) {
         $wt = $this->employee->getWorkingTime(1, $i, $year);
         $monthTemp = 0;
         if ($wt) {
             $nHolidays = bcadd($nHolidays, bcdiv($wt['holidaysByYear'], 12, 4), 4);
             $nbreOfDay = date("t", mktime(0, 0, 0, $i, 1, $year));
             for ($day = 1; $day <= $nbreOfDay; $day++) {
                 $todo = $this->employee->getDayTodo($day, $i, $year);
                 if ($todo) {
                     $totalYearHoursX = bcadd($totalYearHoursX, $todo, 4);
                 }
             }
             $dayPerWeek = 0;
             if ($wt['mondayTime_m'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['mondayTime_a'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['tuesdayTime_m'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['tuesdayTime_a'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['wednesdayTime_m'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['wednesdayTime_a'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['thursdayTime_m'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['thursdayTime_a'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['fridayTime_m'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['fridayTime_a'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['saturdayTime_m'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['saturdayTime_a'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['sundayTime_m'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($wt['sundayTime_a'] > 0) {
                 $dayPerWeek += 0.5;
             }
             if ($dayPerWeek > 0) {
                 $nWeekH = bcadd($nWeekH, bcdiv(bcdiv($wt['holidaysByYear'], 12, 4), $dayPerWeek, 4), 4);
             }
         }
     }
     $this->daysVacation->Text = sprintf("%.02f %s / %.02f " . Prado::localize('weeks'), $nHolidays, Prado::localize('days'), $nWeekH);
     $this->daysVacationLastYear->Text = sprintf("%.02f", $this->employee->geHolidaystMonth($year - 1, 12));
     $this->totalVacation->Text = sprintf("%.02f", bcadd($nHolidays, $this->daysVacationLastYear->Text, 4));
     $this->hoursBalance->Text = sprintf("%.02f", $this->employee->getOvertimeLastYear($year - 1));
     $totalYearHours100 = 0;
     $totalYearHoursX2 = 0;
     $hoursWorked = 0;
     $nbreHolidaysDay = 0;
     $nbreHolidaysHour = 0;
     $nbreAbsenceDay2 = 0;
     $nbreAbsenceHour2 = 0;
     $totalHours = 0;
     for ($month = 1; $month <= 12; $month++) {
         $absentHoursComp = 0;
         $_month = new DateFormat($app->getCulture());
         $months[$month]['month'] = $_month->format("1.{$month}.{$year}", "MMMM");
         $months[$month]['occupancy'] = $this->employee->getPercentage(1, $month, $year);
         $nbreOfDay = date("t", mktime(0, 0, 0, $month, 1, $year));
         $HoursMonth = 0;
         $HoursMonthAtX = 0;
         $HoursDone = 0;
         $nWorkingDay = 0;
         $months[$month]['hours100'] = 0;
         $wt = $this->employee->getWorkingTime(1, $month, $year);
         for ($day = 1; $day <= $nbreOfDay; $day++) {
             $dayTodo = $this->employee->getDayTodo($day, $month, $year);
             $HoursMonth = bcadd($HoursMonth, $dayTodo, 4);
             $tmp = $this->employee->getDayDone($day, $month, $year);
             if ($tmp['compensation'] > 0) {
                 $absentHoursComp = bcadd($absentHoursComp, $tmp['compensation'], 4);
             }
             $HoursDone = bcadd($HoursDone, $tmp['done'], 4);
             if ($dayTodo) {
                 $nWorkingDay++;
             }
             if ($this->employee->isAWorkingDay($year, $month, $day) > 0 && !$this->employee->isNonWorkingDay($day, $month, $year)) {
                 $months[$month]['hours100'] = bcadd($months[$month]['hours100'], bcdiv($wt['hoursByWeek'], $config['daysByWeek'], 4), 4);
             }
         }
         $totalHourWorked = $HoursDone;
         if ($HoursMonth > 0) {
             if ($months[$month]['occupancy'] > 0) {
                 $months[$month]['hours100'] = sprintf("%.02f", $months[$month]['hours100']);
             } else {
                 $months[$month]['hours100'] = sprintf("%.02f", 0);
             }
             $totalYearHours100 = bcadd($months[$month]['hours100'], $totalYearHours100, 2);
         }
         $months[$month]['hoursX'] = sprintf("%.02f", $HoursMonth);
         $totalYearHoursX2 = bcadd($months[$month]['hoursX'], $totalYearHoursX2, 2);
         $defaultHolidayTimeCode = $this->employee->getDefaultHolidaysCounter();
         $holidays = $this->employee->getRequest($year, $month, $defaultHolidayTimeCode);
         $months[$month]['nbreHolidaysDay'] = sprintf("%.02f", $holidays['nbre']);
         $nbreHolidaysDay = bcadd($nbreHolidaysDay, $months[$month]['nbreHolidaysDay'], 2);
         if ($nWorkingDay > 0) {
             $holidaysHour = bcmul($holidays['nbre'], bcdiv($wt['hoursByWeek'], $config['daysByWeek'], 4), 4);
             //  bcmul(bcdiv($HoursMonth,$nWorkingDay,4),$holidays['nbre'],4);
             $nbreHolidaysHour = bcadd($nbreHolidaysHour, $holidaysHour, 2);
         }
         $months[$month]['nbreHolidaysHour'] = sprintf("%.02f", $holidaysHour);
         $totalHourWorked = bcsub($totalHourWorked, $holidaysHour, 4);
         if ($month == 1) {
             $months[$month]['holidayBalance'] = sprintf("%.02f", $this->totalVacation->Text - $months[$month]['nbreHolidaysDay']);
         } else {
             $months[$month]['holidayBalance'] = sprintf("%.02f", $months[$month - 1]['holidayBalance'] - $months[$month]['nbreHolidaysDay']);
         }
         $nbreLeaveHour = $this->employee->getMonthLeaveRequest($month, $year);
         $months[$month]['nbreLeaveHour'] = sprintf("%.02f", $nbreLeaveHour);
         $totalHourWorked = bcsub($totalHourWorked, $nbreLeaveHour, 4);
         $nbreLeaveDay = 0;
         if ($nbreLeaveHour > 0) {
             $wt = $this->employee->getWorkingTime(1, $month, $year);
             $config = $this->employee->getConfig();
             $hoursByDay = bcdiv($wt['hoursByWeek'], $config['daysByWeek'], 4);
             if ($wt['calendarType'] == 1) {
                 $hoursByDay = bcdiv(bcmul($wt['workingPercent'], $hoursByDay, 4), 100, 4);
             }
             $nbreLeaveDay = bcdiv($nbreLeaveHour, $hoursByDay, 4);
         }
         $months[$month]['nbreLeaveDay'] = sprintf("%.02f", $nbreLeaveDay);
         $nbreAbsenceDay = $this->employee->getMonthAbsentRequest($month, $year);
         if ($this->employee->getHoursByDay($month, $year) > 0) {
             $nbreAbsenceDay = bcadd($nbreAbsenceDay, bcdiv($absentHoursComp, $this->employee->getHoursByDay($month, $year), 4), 4);
         }
         $months[$month]['nbreAbsenceDay'] = sprintf("%.02f", $nbreAbsenceDay);
         $nbreAbsenceDay2 = bcadd($nbreAbsenceDay2, $nbreAbsenceDay, 2);
         if ($nWorkingDay > 0) {
             $wt = $this->employee->getWorkingTime(1, $month, $year);
             if ($wt['calendarType'] == 1) {
                 $nbreAbsenceHour = bcmul(bcdiv($HoursMonth, $nWorkingDay, 4), $nbreAbsenceDay, 4);
             } else {
                 $nbreAbsenceHour = bcmul(bcdiv($months[$month]['hours100'], $nWorkingDay, 4), $nbreAbsenceDay, 4);
             }
             $nbreAbsenceHour2 = bcadd($nbreAbsenceHour, $nbreAbsenceHour2, 2);
         }
         $months[$month]['nbreAbsenceHour'] = sprintf("%.02f", $nbreAbsenceHour);
         $totalHourWorked = bcsub($totalHourWorked, $nbreAbsenceHour, 4);
         $months[$month]['hoursWorked'] = sprintf("%.02f", $totalHourWorked);
         $hoursWorked = bcadd($hoursWorked, $months[$month]['hoursWorked'], 2);
         $months[$month]['totalHours'] = sprintf("%.02f", $HoursDone);
         $totalHours = bcadd($totalHours, $HoursDone, 2);
         $months[$month]['monthBalance'] = bcsub($months[$month]['totalHours'], $months[$month]['hoursX'], 2);
         $totalYearHoursX = bcsub($totalYearHoursX, $months[$month]['totalHours'], 2);
         $months[$month]['hoursDueYear'] = sprintf("%.02f", $totalYearHoursX);
         $hoursDueYearSubHolidays = 0;
         if ($nWorkingDay > 0) {
             $hoursDueYearSubHolidays = bcmul(bcdiv($HoursMonth, $nWorkingDay, 4), $months[$month]['holidayBalance'], 4);
         }
         $hoursDueYearSubHolidays = bcsub($totalYearHoursX, $hoursDueYearSubHolidays, 2);
         $months[$month]['hoursDueYearSubHolidays'] = sprintf("%.02f", $hoursDueYearSubHolidays);
         if (12 - $month > 0) {
             $months[$month]['average'] = bcdiv($months[$month]['hoursDueYearSubHolidays'], 12 - $month, 2);
         } else {
             $months[$month]['average'] = "";
         }
     }
     $months[13] = array();
     $months[14]['month'] = Prado::localize('Totals');
     $months[14]['hours100'] = sprintf("%.02f", $totalYearHours100);
     $months[14]['hoursX'] = sprintf("%.02f", $totalYearHoursX2);
     $months[14]['hoursWorked'] = sprintf("%.02f", $hoursWorked);
     $months[14]['nbreHolidaysDay'] = sprintf("%.02f", $nbreHolidaysDay);
     $months[14]['nbreHolidaysHour'] = sprintf("%.02f", $nbreHolidaysHour);
     $months[14]['nbreAbsenceDay'] = sprintf("%.02f", $nbreAbsenceDay2);
     $months[14]['nbreAbsenceHour'] = sprintf("%.02f", $nbreAbsenceHour2);
     $months[14]['totalHours'] = sprintf("%.02f", $totalHours);
     $months[15] = array();
     $months[16]['month'] = Prado::localize('Total do be done');
     $months[16]['hoursX'] = sprintf("%.02f", $totalYearHoursX2 - $this->hoursBalance->Text);
     return $months;
 }
Exemplo n.º 4
0
 /**
  * Renders the localized version of the date-time value.
  * If the culture is not specified, the default application
  * culture will be used.
  * This method overrides parent's implementation.
  */
 protected function renderBody()
 {
     $app = $this->Application->getGlobalization();
     //initialized the default class wide formatter
     if (is_null(self::$formatter)) {
         self::$formatter = new DateFormat($app->Culture);
     }
     $culture = $this->getCulture();
     $value = $this->getValue();
     //return the specific cultural formatted date time
     if (strlen($culture) && $app->Culture !== $culture) {
         $formatter = new DateFormat($culture);
         return $formatter->format($value, $this->getPattern());
     }
     $charset = $this->getCharset();
     if (empty($charset)) {
         $charset = 'UTF-8';
     }
     //return the application wide culture formatted date time.
     return self::$formatter->format($value, $this->getPattern(), $charset);
 }
function smarty_modifier_dateformat($input)
{
    return DateFormat::format($input);
}