/** * Helper function - creates an object of type SMWTimeValue based * on a "Julian day" integer */ protected static function jdToTimeValue($jd) { $timeDataItem = SMWDITime::newFromJD($jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT); $timeValue = new SMWTimeValue('_dat'); $timeValue->setDataItem($timeDataItem); return $timeValue; }
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); }
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; }
/** * Sets a date/time value at the given col,row location * * @param $object the raw data value object */ protected function setTimeDataValue(\SMWTimeValue $object) { $type = PHPExcel_Cell_DataType::TYPE_NUMERIC; $value = \PHPExcel_Shared_Date::stringToExcel(str_replace('T', ' ', $object->getISO8601Date())); $this->sheet->getCellByColumnAndRow($this->colNum, $this->rowNum)->setValueExplicit($value, $type); if (!$this->styled) { $this->sheet->getStyleByColumnAndRow($this->colNum, $this->rowNum)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY); } }
public function testLOCLOutputFormatWithTimeZoneOnSpecificAnnotatedLanguage() { $timeValue = new TimeValue('_dat'); $timeValue->setUserValue('2015-02-28 12:12:00 A'); $timeValue->setOption(TimeValue::OPT_USER_LANGUAGE, 'en'); $timeValue->setOutputFormat('LOCL@ja#TZ'); $instance = new TimeValueFormatter($timeValue); $this->assertEquals('2015年2月28日 (土) 12:12:00 A', $instance->format(TimeValueFormatter::HTML_LONG)); $this->assertEquals('2015-02-28 12:12:00 A', $instance->format(TimeValueFormatter::WIKI_SHORT)); }
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; }
protected static function getWikiTextDateFromSMWDITime(SMWDITime $di) { $val = new SMWTimeValue(SMWDataItem::TYPE_TIME); $val->setDataItem($di); return $val->getShortWikiText(); }
/** * 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; }
/** * Method to create a dataitem from a type ID and array of DB keys. * Throws SMWDataItemException if problems occur, to get our callers * used to it. * * @param $typeid string id for the given type * @param $dbkeys array of mixed * * @return SMWDataItem */ public static function dataItemFromDBKeys($typeid, $dbkeys) { switch (SMWDataValueFactory::getDataItemId($typeid)) { case SMWDataItem::TYPE_ERROR: case SMWDataItem::TYPE_NOTYPE: break; case SMWDataItem::TYPE_NUMBER: return SMWDINumber::doUnserialize($dbkeys[0]); case SMWDataItem::TYPE_STRING: return new SMWDIString($dbkeys[0]); case SMWDataItem::TYPE_BLOB: return new SMWDIBlob($dbkeys[0]); case SMWDataItem::TYPE_BOOLEAN: return new SMWDIBoolean($dbkeys[0] == '1'); case SMWDataItem::TYPE_URI: if ($typeid == '__typ' && $dbkeys[0][0] == '_') { // b/c: old data stored as type ids return SMWTypesValue::getTypeUriFromTypeId($dbkeys[0]); } else { return SMWDIUri::doUnserialize($dbkeys[0]); } case SMWDataItem::TYPE_TIME: $timedate = explode('T', $dbkeys[0], 2); if (count($dbkeys) == 2 && count($timedate) == 2) { $date = reset($timedate); $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false; if (end($timedate) === '' || SMWTimeValue::parseTimeString(end($timedate), $hours, $minutes, $seconds, $timeoffset) == true) { $d = explode('/', $date, 3); if (count($d) == 3) { list($year, $month, $day) = $d; } elseif (count($d) == 2) { list($year, $month) = $d; } elseif (count($d) == 1) { list($year) = $d; } if ($month === '') { $month = false; } if ($day === '') { $day = false; } $calendarmodel = SMWDITime::CM_GREGORIAN; return new SMWDITime($calendarmodel, $year, $month, $day, $hours, $minutes, $seconds); } } break; case SMWDataItem::TYPE_GEO: return new SMWDIGeoCoord(array('lat' => (double) $dbkeys[0], 'lon' => (double) $dbkeys[1])); case SMWDataItem::TYPE_CONTAINER: // provided for backwards compatibility only; // today containers are read from the store as substructures, // not retrieved as single complex values $semanticData = SMWContainerSemanticData::makeAnonymousContainer(); foreach (reset($dbkeys) as $value) { if (is_array($value) && count($value) == 2) { $diP = new SMWDIProperty(reset($value), false); $diV = self::dataItemFromDBKeys($diP->findPropertyTypeID(), end($value)); $semanticData->addPropertyObjectValue($diP, $diV); } } return new SMWDIContainer($semanticData); case SMWDataItem::TYPE_WIKIPAGE: if ($typeid == '__spf') { $pagedbkey = str_replace(' ', '_', $dbkeys[0]); return new SMWDIWikiPage($pagedbkey, SF_NS_FORM, ''); } elseif (count($dbkeys) >= 5) { // with subobject name (and sortkey) return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2], $dbkeys[4]); } elseif (count($dbkeys) >= 3) { // without subobject name (just for b/c) return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2]); } break; case SMWDataItem::TYPE_CONCEPT: if (count($dbkeys) >= 5) { return new SMWDIConcept($dbkeys[0], smwfXMLContentEncode($dbkeys[1]), $dbkeys[2], $dbkeys[3], $dbkeys[4]); } break; case SMWDataItem::TYPE_PROPERTY: return new SMWDIProperty($dbkeys[0], false); } throw new SMWDataItemException('Failed to create data item from DB keys.'); }