Esempio n. 1
0
 static function parseDateSMW($date)
 {
     $actual_date = new SMWTimeValue('_dat');
     $actual_date->setUserValue($date);
     $year = $actual_date->getYear();
     // TODO - the code to convert from negative to BC notation
     // should be in SMW itself.
     if ($year < 0) {
         $year = $year * -1 + 1 . ' BC';
     }
     // Use precision of the date to determine whether we should
     // also set the month and day.
     if (method_exists($actual_date->getDataItem(), 'getPrecision')) {
         $precision = $actual_date->getDataItem()->getPrecision();
         if ($precision > SMWDITime::PREC_Y) {
             $month = $actual_date->getMonth();
         }
         if ($precision > SMWDITime::PREC_YM) {
             $day = $actual_date->getDay();
         }
     } else {
         // There's some sort of error - make everything blank.
         $year = null;
     }
     return array($year, $month, $day);
 }
Esempio n. 2
0
 public static function getMainHTML($date, $input_name, $is_mandatory, $is_disabled, $other_args)
 {
     global $sfgTabIndex, $wgAmericanDates;
     if ($date) {
         // Can show up here either as an array or a string,
         // depending on whether it came from user input or a
         // wiki page.
         if (is_array($date)) {
             $year = $date['year'];
             $month = $date['month'];
             $day = $date['day'];
         } else {
             // handle 'default=now'
             if ($date == 'now') {
                 global $wgLocaltimezone;
                 if (isset($wgLocaltimezone)) {
                     $serverTimezone = date_default_timezone_get();
                     date_default_timezone_set($wgLocaltimezone);
                 }
                 $date = date('Y/m/d');
                 if (isset($wgLocaltimezone)) {
                     date_default_timezone_set($serverTimezone);
                 }
             }
             $actual_date = new SMWTimeValue('_dat');
             $actual_date->setUserValue($date);
             $year = $actual_date->getYear();
             // TODO - the code to convert from negative to
             // BC notation should be in SMW itself.
             if ($year < 0) {
                 $year = $year * -1 + 1 . ' BC';
             }
             $month = $actual_date->getMonth();
             $day = $actual_date->getDay();
         }
     } else {
         $cur_date = getdate();
         $year = $cur_date['year'];
         $month = $cur_date['month'];
         $day = null;
         // no need for day
     }
     $text = "";
     $disabled_text = $is_disabled ? 'disabled' : '';
     $monthInput = self::monthDropdownHTML($month, $input_name, $is_disabled);
     $dayInput = '	<input tabindex="' . $sfgTabIndex . '" class="dayInput" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>';
     if ($wgAmericanDates) {
         $text .= "{$monthInput}\n{$dayInput}\n";
     } else {
         $text .= "{$dayInput}\n{$monthInput}\n";
     }
     $text .= '	<input tabindex="' . $sfgTabIndex . '" class="yearInput" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
     return $text;
 }
 /**
  * This method extract a date string formatted for ganttchart from a SMWTimeValue object.
  *
  * @param $dv		SMWTimeValue, date that is to be converted
  * @return			string in form MM/DD/YYYY HH:MM:SS
  */
 public function getGanttDate(SMWTimeValue $dv, $isend = false)
 {
     $year = $dv->getYear();
     if ($year > 9999 || $year < -9998) {
         return '';
     }
     // ISO range is limited to four digits
     $year = number_format($year, 0, '.', '');
     $time = $dv->getTimeString(false);
     if ($time == false && $isend) {
         // increment by one day, compute date to cover leap years etc.
         $dv = SMWDataValueFactory::newTypeIDValue('_dat', $dv->getWikiValue() . 'T00:00:00+24:00');
     }
     $month = $dv->getMonth();
     if (strlen($month) == 1) {
         $month = '0' . $month;
     }
     $day = $dv->getDay();
     if (strlen($day) == 1) {
         $day = '0' . $day;
     }
     $result = $month . '/' . $day . '/' . $year;
     if ($time != false) {
         $result .= " {$time}";
     }
     return $result;
 }
 public static function getMainHTML($date, $input_name, $is_mandatory, $is_disabled, $other_args)
 {
     global $sfgTabIndex, $wgAmericanDates;
     $year = $month = $day = null;
     if ($date) {
         // Can show up here either as an array or a string,
         // depending on whether it came from user input or a
         // wiki page.
         if (is_array($date)) {
             $year = $date['year'];
             $month = $date['month'];
             $day = $date['day'];
         } else {
             // handle 'default=now'
             if ($date == 'now') {
                 global $wgLocaltimezone;
                 if (isset($wgLocaltimezone)) {
                     $serverTimezone = date_default_timezone_get();
                     date_default_timezone_set($wgLocaltimezone);
                 }
                 $date = date('Y/m/d');
                 if (isset($wgLocaltimezone)) {
                     date_default_timezone_set($serverTimezone);
                 }
             }
             $actual_date = new SMWTimeValue('_dat');
             $actual_date->setUserValue($date);
             $year = $actual_date->getYear();
             // TODO - the code to convert from negative to
             // BC notation should be in SMW itself.
             if ($year < 0) {
                 $year = $year * -1 + 1 . ' BC';
             }
             // Use precision of the date to determine
             // whether we should also set the month and
             // day.
             if (method_exists($actual_date->getDataItem(), 'getPrecision')) {
                 $precision = $actual_date->getDataItem()->getPrecision();
                 if ($precision > SMWDITime::PREC_Y) {
                     $month = $actual_date->getMonth();
                 }
                 if ($precision > SMWDITime::PREC_YM) {
                     $day = $actual_date->getDay();
                 }
             } else {
                 // There's some sort of error - make
                 // everything blank.
                 $year = null;
             }
         }
     } else {
         // Just keep everything at null.
     }
     $text = "";
     $disabled_text = $is_disabled ? 'disabled' : '';
     $monthInput = self::monthDropdownHTML($month, $input_name, $is_disabled);
     $dayInput = '	<input tabindex="' . $sfgTabIndex . '" class="dayInput" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>';
     if ($wgAmericanDates) {
         $text .= "{$monthInput}\n{$dayInput}\n";
     } else {
         $text .= "{$dayInput}\n{$monthInput}\n";
     }
     $text .= '	<input tabindex="' . $sfgTabIndex . '" class="yearInput" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
     return $text;
 }
	/**
	 * Extract a date string formatted for iCalendar from a SMWTimeValue object.
	 */
	static private function parsedate( SMWTimeValue $dv, $isend = false ) {
		$year = $dv->getYear();
		if ( ( $year > 9999 ) || ( $year < -9998 ) ) return ''; // ISO range is limited to four digits
		
		$year = number_format( $year, 0, '.', '' );
		$time = str_replace( ':', '', $dv->getTimeString( false ) );
		
		if ( ( $time == false ) && ( $isend ) ) { // increment by one day, compute date to cover leap years etc.
			$dv = SMWDataValueFactory::newTypeIDValue( '_dat', $dv->getWikiValue() . 'T00:00:00-24:00' );
		}
		
		$month = $dv->getMonth();
		if ( strlen( $month ) == 1 ) $month = '0' . $month;
		
		$day = $dv->getDay();
		if ( strlen( $day ) == 1 ) $day = '0' . $day;
		
		$result = $year . $month . $day;
		
		if ( $time != false ) $result .= "T$time";
		
		return $result;
	}