예제 #1
0
 /**
  * Formats the date of a Timestamp object according to the given format:
  * This function assumes that the timestamp is local and it converts it
  * to GMT before formatting.
  *
  * (compatible with PHP):<ul>
  * <li>%a abbreviated weekday</li>
  * <li>%A	complete weekday</li>
  * <li>%b	abbreviated month</li>
  * <li>%B	long month</li>
  * <li>%d	day of the month, 2 digits with leading zero</li>
  * <li>%j   day of the month, numeric (without leading zero)</li>
  * <li>%H	hours, in 24-h format</li>
  * <li>%I	hours, in 12-h format (without leading zero)</li>
  * <li>%p   returns 'am' or 'pm'</li>
  * <li>%P   returns 'AM' or 'PM'</li>
  * <li>%M	minutes</li>
  * <li>%m	month number, from 00 to 12</li>
  * <li>%S	seconds</li>
  * <li>%y	2-digit year representation</li>
  * <li>%Y	4-digit year representation</li>
  * <li>%O   Difference to Greenwich time (GMT) in hours (Will always be +0000)</li>
  * <li>%%	the '%' character
  * </ul>
  * (these have been added by myself and are therefore incompatible with php)<ul>
  * <li>%T	"_day_ of _month_", where the day is in ordinal form and 'month' is the name of the month</li>
  * <li>%D	cardinal representation of the day</li>
  * </ul>
  */
 function formatDateGMT($timeStamp, $format = null, $blog = null)
 {
     // load the file if it hadn't been loaded yet
     if (!is_array($this->_messages)) {
         $this->_loadLocaleFile();
     }
     if ($blog) {
         //
         // The blog was specified.  Use it to get the time offset
         //
         $timeDiff = 0;
         $blogSettings = $blog->getSettings();
         $timeDiff = $blogSettings->getValue('time_offset');
         $timeDiff *= -1;
         if ($timeDiff > 0) {
             $timeStamp->addSeconds($timeDiff * 3600);
         } else {
             $timeStamp->subtractSeconds($timeDiff * -3600);
         }
     }
     // Convert this timestamp to on that is in GMT
     $strTimeStamp = $timeStamp->getTimestamp();
     // Now have a local time stamp
     // Is this step really necessary, since we previously had a time stamp
     $time = mktime(substr($strTimeStamp, 8, 2), substr($strTimeStamp, 10, 2), substr($strTimeStamp, 12, 2), substr($strTimeStamp, 4, 2), substr($strTimeStamp, 6, 2), substr($strTimeStamp, 0, 4));
     // This does not take into account the time offset that the user
     // specified, since we are converting the time to GMT.  Since the
     // offset is just used to handle time zone differences, it is not
     // necessary, as the time GMT is still the same.
     // timestamp only returns the values in english, so we should translate
     // them before using
     $monthId = gmdate("n", $time);
     $monthStr = $this->_messages["months"][$monthId - 1];
     //print("monthstr: $monthStr");
     // and the same for the weekdays
     $weekdayId = gmdate("w", $time);
     $weekday = $this->_messages["days"][$weekdayId];
     // if the user did not specify a format, let's use the default one
     if ($format == null) {
         $format = $this->_dateFormat;
     }
     // now we can continue normally
     $values["%a"] = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($weekday), 0, 3)) : substr($weekday, 0, 3);
     $values["%A"] = $weekday;
     $values["%b"] = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($monthStr), 0, 3)) : substr($monthStr, 0, 3);
     $values["%B"] = $monthStr;
     $values["%d"] = gmdate("d", $time);
     $values["%e"] = intval(gmdate("d", $time));
     $values["%j"] = gmdate("j", $time);
     $values["%H"] = gmdate("H", $time);
     $values["%I"] = gmdate("g", $time);
     $values["%p"] = gmdate("a", $time);
     $values["%P"] = gmdate("A", $time);
     $values["%M"] = gmdate("i", $time);
     $values["%m"] = gmdate("m", $time);
     $values["%S"] = gmdate("s", $time);
     $values["%y"] = gmdate("y", $time);
     $values["%Y"] = gmdate("Y", $time);
     $values["%O"] = "+0000";
     $values["%%"] = "%";
     $values["%T"] = $this->getDateOrdinal(gmdate("d", $time)) . " " . $this->tr("of") . " " . $monthStr;
     $values["%D"] = $this->getDateOrdinal(gmdate("d", $time));
     /* Start Hack By FiFtHeLeMeNt For Persian Language */
     list($jyear, $jmonth, $jday) = JalaliCalendar::gregorian_to_jalali(gmdate("Y", $time), gmdate("m", $time), gmdate("d", $time));
     $values["%q"] = JalaliCalendar::Convertnumber2farsi($jyear);
     $values["%w"] = JalaliCalendar::Convertnumber2farsi($jmonth);
     $values["%o"] = JalaliCalendar::Convertnumber2farsi($jday);
     $values["%R"] = JalaliCalendar::monthname($jmonth);
     $values["%T"] = JalaliCalendar::Convertnumber2farsi(gmdate("H", $time));
     $values["%U"] = JalaliCalendar::Convertnumber2farsi(gmdate("i", $time));
     /* End Hack By FiFtHeLeMeNt For Persian Language */
     $text = $format;
     foreach (array_keys($values) as $key) {
         if (ereg($key, $text)) {
             $text = str_replace($key, $values[$key], $text);
         }
     }
     return $text;
 }
 function inputTimeToGregorian($usertime)
 {
     list($jfdate, $ftime) = preg_split('/ /', $usertime);
     list($fhour, $fminut, $fsec) = preg_split('/:/', $ftime);
     // convert persian numbers to english if exist
     $hour = JalaliCalendar::Convertnumber2english($fhour);
     $minut = JalaliCalendar::Convertnumber2english($fminut);
     $sec = JalaliCalendar::Convertnumber2english($fsec);
     list($jfyear, $jfmonth, $jfday) = preg_split('/-/', $jfdate);
     // convert persian numbers to english if exist
     $jyear = JalaliCalendar::Convertnumber2english($jfyear);
     $jmonth = JalaliCalendar::Convertnumber2english($jfmonth);
     $jday = JalaliCalendar::Convertnumber2english($jfday);
     if (_USE_HEGIRADATE) {
         $maket = JalaliCalendar::jmaketime($hour - _JDF_TZhours, $minut - _JDF_TZminute, $sec, $jmonth, $jday, $jyear);
     } else {
         $maket = mktime($hour, $minut, $sec, $jmonth, $jday, $jyear);
     }
     $usertime = date("Y-m-d H:i:s", $maket);
     return $usertime;
 }