function pleac_Parsing_Dates_and_Times_from_Strings()
{
    // 'strtotime' parses a textual date expression by attempting a 'best guess' at
    // the format, and either fails, or generates a timestamp. Timestamp could be fed
    // into any one of the various functions; example:
    $timestamp = strtotime('1998-06-03');
    echo strftime('%Y-%m-%d', $timestamp) . "\n";
    // 'strptime' parses a textual date expression according to a specified format,
    // and returns an array of date components; components can be easily dumped
    print_r(strptime('1998-06-03', '%Y-%m-%d'));
    // ----------------------------
    // Parse date string according to format
    $darr = strptime('1998-06-03', '%Y-%m-%d');
    if (!empty($darr)) {
        // Show date components in 'debug' form
        print_r($darr);
        // Check whether there was a parse error i.e. one or more components could not
        // be extracted from the string
        if (empty($darr['unparsed'])) {
            // Properly parsed date, so validate required components using, 'checkdate'
            if (checkdate($darr['tm_mon'] + 1, $darr['tm_mday'], $darr['tm_year'] + 1900)) {
                echo "Parsed date verified as correct\n";
            } else {
                echo "Parsed date failed verification\n";
            }
        } else {
            echo "Date string parse not complete; failed components: {$darr['unparsed']}\n";
        }
    } else {
        echo "Date string could not be parsed\n";
    }
}
예제 #2
0
 public static function getWeekday($date)
 {
     $d = strptime($date, '%Y-%m-%d');
     $timestamp = mktime(0, 0, 0, $d['tm_mon'] + 1, $d['tm_mday'] + $i, $d['tm_year'] + 1900);
     switch ((int) date("w", $timestamp)) {
         case 0:
             $day = "неделя";
             break;
         case 1:
             $day = "понеделник";
             break;
         case 2:
             $day = "вторник";
             break;
         case 3:
             $day = "сряда";
             break;
         case 4:
             $day = "четвъртък";
             break;
         case 5:
             $day = "петък";
             break;
         case 6:
             $day = "събота";
             break;
         default:
             brak;
     }
     return $day;
 }
예제 #3
0
파일: DateTest.php 프로젝트: pixlr/ZCE-2
 public function testStrPTime()
 {
     $date = strptime('01/01/1970', "%d/%m/%Y");
     $this->assertEquals(1, $date['tm_mday']);
     $this->assertEquals(0, $date['tm_mon']);
     $this->assertEquals(70, $date['tm_year']);
 }
예제 #4
0
function wpp_date_to_unix($date)
{
    $date_slash = str_replace("/", "-", $date);
    $date_format = strptime($date_slash, '%m-%d-%Y');
    $timestamp = mktime(0, 0, 0, $date_format['tm_mon'] + 1, $date_format['tm_mday'], $date_format['tm_year'] + 1900);
    return $timestamp;
}
 /**
  * Required parameter check
  * @param $params params extracted from the POST
  */
 protected function validateParams($params)
 {
     $required = array('eventid', 'startdate', 'enddate', 'increment', 'userdefs');
     foreach ($required as $arg) {
         if (!isset($params[$arg])) {
             $this->dieUsageMsg(array('missingparam', $arg));
         }
     }
     // check if event id parses to an int greater than zero
     if ((int) $params['eventid'] < 0) {
         $this->dieUsage('Invalid event ID', 'badeventid');
     }
     // check start and end date are of proper format
     if ($params['startdate'] != 0 && strptime(SpecialClickTracking::space_out_date($params['startdate']), "%Y %m %d") === false) {
         $this->dieUsage("startdate not in YYYYMMDD format: <<{$params['startdate']}>>", 'badstartdate');
     }
     if ($params['enddate'] != 0 && strptime(SpecialClickTracking::space_out_date($params['enddate']), "%Y %m %d") === false) {
         $this->dieUsage("enddate not in YYYYMMDD format: <<{$params['enddate']}>>", 'badenddate');
     }
     // check if increment is a positive int
     if ((int) $params['increment'] <= 0) {
         $this->dieUsage('Invalid increment', 'badincrement');
     }
     if (json_decode($params['userdefs']) == null) {
         $this->dieUsage("Invalid JSON encoding <<{$params['userdefs']}>>", 'badjson');
     }
 }
예제 #6
0
 /**
  * Parses single line of http log into array structure
  *
  * @param  string
  * @return array
  */
 public static function parse($line)
 {
     // Coarse match
     if (!preg_match('/^([^ ]+) ([^ ]+) ([^ ]+) \\[([^ ]+) ([^\\]]+)] "([^"]+)" ([0-9]+) ((?:[0-9]+)|-) "([^"]+)" "([^"]+)"$/', $line, $matches)) {
         throw new A2o_Parser_Log_Http_Exception("Unable to parse line:  \n{$line}\n");
     }
     $res = array('host' => $matches[1], 'user' => $matches[3], 'date_time' => $matches[4], 'time_zone' => $matches[5], 'request_line' => $matches[6], 'http_status' => $matches[7], 'data_sent' => $matches[8], 'referer' => $matches[9], 'user_agent' => $matches[10]);
     $dateTime = $matches[4];
     $timeZone = $matches[5];
     $requestLine = $matches[6];
     // Get unix timestamp
     $dateTimeArray = strptime("{$dateTime} {$timeZone}", '%d/%b/%Y:%H:%M:%S %z');
     if ($dateTimeArray === FALSE) {
         throw new A2o_Parser_Log_Http_Exception("Unable to parse datetime line:  \n{$dateTime}\n");
     }
     $timestamp = mktime($dateTimeArray['tm_hour'], $dateTimeArray['tm_min'], $dateTimeArray['tm_sec'], $dateTimeArray['tm_mon'] + 1, $dateTimeArray['tm_mday'], $dateTimeArray['tm_year'] + 1900);
     $res['timestamp'] = $timestamp;
     // Parse the request line
     if (!preg_match('/^([A-Z]+) ([^ ]+) (HTTP\\/1.[01])\\s*$/', $requestLine, $matches)) {
         echo "{$line}\n";
         throw new A2o_Parser_Log_Http_Exception("Unable to parse request line:  \n'{$requestLine}'\n");
     }
     $res['request_method'] = $matches[1];
     $res['request_file'] = $matches[2];
     $res['http_protocol_version'] = $matches[3];
     // Return to caller
     return $res;
 }
예제 #7
0
 public function clean($value)
 {
     parent::clean($value);
     $out = null;
     foreach ($this->input_formats as $format) {
         if (false !== ($date = strptime($value, $format))) {
             $day = str_pad($date['tm_mday'], 2, '0', STR_PAD_LEFT);
             $month = str_pad($date['tm_mon'] + 1, 2, '0', STR_PAD_LEFT);
             $year = str_pad($date['tm_year'] + 1900, 4, '0', STR_PAD_LEFT);
             $h = str_pad($date['tm_hour'], 2, '0', STR_PAD_LEFT);
             $m = str_pad($date['tm_min'], 2, '0', STR_PAD_LEFT);
             $s = $date['tm_sec'];
             if ($s > 59) {
                 $s = 59;
             }
             $s = str_pad($s, 2, '0', STR_PAD_LEFT);
             $out = $year . '-' . $month . '-' . $day . ' ' . $h . ':' . $m . ':' . $s;
             break;
         }
     }
     if ($out !== null) {
         // We internally use GMT, so we convert it to a GMT date.
         return gmdate('Y-m-d H:i:s', strtotime($out));
     }
     throw new Pluf_Form_Invalid(__('Enter a valid date/time.'));
 }
예제 #8
0
 /**
  * @Route("/admin/parser")
  * @Method("GET")
  * @Template()
  */
 public function parserAction()
 {
     set_time_limit(0);
     $rootDir = $this->get('kernel')->getRootDir();
     $content = file_get_contents(realpath($rootDir . '/../docs/google-groups-posts.bkp.html'));
     $crawler = new Crawler($content);
     $subjectFilterPrefix = 'pergunta';
     $em = $this->get('doctrine')->getManager();
     $crawler->filter('body > table > tbody > tr > td > div > div > div:first-child')->each(function (Crawler $node, $i) use(&$subjectFilterPrefix, $em) {
         $subject = $node->filter('a')->first();
         $author = $node->filter('div:first-child > div')->attr('data-name');
         $time = $node->filter('div')->last()->children()->attr('title');
         setlocale(LC_ALL, NULL);
         setlocale(LC_ALL, 'pt_BR');
         if (substr(strtolower(utf8_decode($subject->text())), 0, strlen($subjectFilterPrefix)) == $subjectFilterPrefix) {
             $timeParts = explode(',', utf8_decode($time));
             $timeParsed = strptime(end($timeParts), '%d de %B de %Y %Hh%Mmin%Ss');
             $createdAt = new \DateTime(date('Y-m-d h:i:s', mktime($timeParsed['tm_hour'], $timeParsed['tm_min'], $timeParsed['tm_sec'], 1, $timeParsed['tm_yday'] + 1, $timeParsed['tm_year'] + 1900)));
             $entity = $em->getRepository('CekurteZCPEBundle:Parser')->findOneBy(array('subject' => utf8_decode($subject->text())));
             if (!$entity instanceof Parser) {
                 $parser = new Parser();
                 $parser->setSubject(utf8_decode($subject->text()))->setUrl($subject->attr('href'))->setAuthor(utf8_decode($author))->setCreatedAt($createdAt);
                 $em->persist($parser);
                 $em->flush();
             }
         }
     });
     return array();
 }
예제 #9
0
 /**
  * Returns TRUE if submitted value validates according to rule
  *
  * @return boolean
  * @see \TYPO3\CMS\Form\Validation\ValidatorInterface::isValid()
  */
 public function isValid()
 {
     if ($this->requestHandler->has($this->fieldName)) {
         $value = $this->requestHandler->getByMethod($this->fieldName);
         if (function_exists('strptime')) {
             $parsedDate = strptime($value, $this->format);
             $parsedDateYear = $parsedDate['tm_year'] + 1900;
             $parsedDateMonth = $parsedDate['tm_mon'] + 1;
             $parsedDateDay = $parsedDate['tm_mday'];
             return checkdate($parsedDateMonth, $parsedDateDay, $parsedDateYear);
         } else {
             // %a => D : An abbreviated textual representation of the day (conversion works only for english)
             // %A => l : A full textual representation of the day (conversion works only for english)
             // %d => d : Day of the month, 2 digits with leading zeros
             // %e => j : Day of the month, 2 digits without leading zeros
             // %j => z : Day of the year, 3 digits with leading zeros
             // %b => M : Abbreviated month name, based on the locale (conversion works only for english)
             // %B => F : Full month name, based on the locale (conversion works only for english)
             // %h => M : Abbreviated month name, based on the locale (an alias of %b) (conversion works only for english)
             // %m => m : Two digit representation of the month
             // %y => y : Two digit representation of the year
             // %Y => Y : Four digit representation for the year
             $dateTimeFormat = str_replace(array('%a', '%A', '%d', '%e', '%j', '%b', '%B', '%h', '%m', '%y', '%Y'), array('D', 'l', 'd', 'j', 'z', 'M', 'F', 'M', 'm', 'y', 'Y'), $this->format);
             $dateTimeObject = date_create_from_format($dateTimeFormat, $value);
             if ($dateTimeObject === FALSE) {
                 return FALSE;
             }
             return $value === $dateTimeObject->format($dateTimeFormat);
         }
     }
     return TRUE;
 }
예제 #10
0
 public function action($what, $cat, &$ret, $limit, $useGlobalCats)
 {
     $added = 0;
     $url = 'http://torrentz.eu';
     if ($useGlobalCats) {
         $categories = array('all' => '', 'movies' => ' movies', 'tv' => ' tv', 'music' => ' music', 'games' => ' games', 'anime' => ' anime', 'software' => ' software', 'pictures' => ' pictures', 'books' => ' books');
     } else {
         $categories =& $this->categories;
     }
     if (!array_key_exists($cat, $categories)) {
         $cat = $categories['all'];
     } else {
         $cat = $categories[$cat];
     }
     $maxPage = 10;
     $updateMaxPage = true;
     for ($pg = 0; $pg < $maxPage; $pg++) {
         $cli = $this->fetch($url . '/search?q=' . $what . $cat . '&p=' . $pg);
         if ($cli === false) {
             break;
         }
         // max page
         if ($updateMaxPage) {
             $updateMaxPage = false;
             if (!preg_match('`<a href="/search\\?q=[^"]*&amp;p=\\d+">(?P<maxpage>\\d+)</a> <a href="/search\\?q=[^"]*&amp;p=\\d+">Next &raquo;</a>`siU', $cli->results, $matches)) {
                 $maxPage = 0;
             } else {
                 $maxPage = $matches["maxpage"];
             }
         }
         // torrents
         $res = preg_match_all('`<dl><dt.*><a href="/(?P<hash>[0-9a-fA-F]+?)">(?P<name>.+)</a> &#187; ' . '(?P<cat>.*)</dt><dd>.*' . '<span class="a"><span title="(?P<date>.*)">.*</span></span>' . '<span class="s">(?P<size>.*)</span> <span class="u">(?P<seeds>.*)</span>' . '<span class="d">(?P<leech>.*)</span></dd></dl>' . '`siU', $cli->results, $matches);
         if ($res) {
             for ($i = 0; $i < $res; $i++) {
                 $link = "http://zoink.it/torrent/" . strtoupper($matches["hash"][$i]) . ".torrent";
                 if (!array_key_exists($link, $ret)) {
                     $item = $this->getNewEntry();
                     $item["cat"] = self::removeTags($matches["cat"][$i]);
                     $item["desc"] = $url . "/" . $matches["hash"][$i];
                     $item["name"] = self::removeTags($matches["name"][$i]);
                     $item["size"] = self::formatSize($matches["size"][$i]);
                     $item["seeds"] = intval($matches["seeds"][$i]);
                     $item["peers"] = intval($matches["leech"][$i]);
                     $tms = self::removeTags($matches["date"][$i]);
                     $tm = strptime($tms, '%a, %d %b %Y %T');
                     if ($tm !== false) {
                         $item["time"] = mktime($tm["tm_hour"], $tm["tm_min"], $tm["tm_sec"], $tm["tm_mon"] + 1, $tm["tm_mday"], $tm["tm_year"] + 1900);
                     }
                     $ret[$link] = $item;
                     $added++;
                     if ($added >= $limit) {
                         return;
                     }
                 }
             }
         } else {
             break;
         }
     }
 }
예제 #11
0
 /**
  * @param string $str
  * @return int
  */
 private function parseFormatedDate($str)
 {
     KalturaLog::debug("parseFormatedDate({$str})");
     if (function_exists('strptime')) {
         $ret = strptime($str, self::BULK_UPLOAD_DATE_FORMAT);
         if ($ret) {
             KalturaLog::debug("Formated Date [{$ret}] " . date('Y-m-d\\TH:i:s', $ret));
             return $ret;
         }
     }
     $fields = null;
     $regex = $this->getDateFormatRegex($fields);
     $values = null;
     if (!preg_match($regex, $str, $values)) {
         return null;
     }
     $hour = 0;
     $minute = 0;
     $second = 0;
     $month = 0;
     $day = 0;
     $year = 0;
     $is_dst = 0;
     foreach ($fields as $index => $field) {
         $value = $values[$index + 1];
         switch ($field) {
             case 'Y':
                 $year = intval($value);
                 break;
             case 'm':
                 $month = intval($value);
                 break;
             case 'd':
                 $day = intval($value);
                 break;
             case 'H':
                 $hour = intval($value);
                 break;
             case 'i':
                 $minute = intval($value);
                 break;
             case 's':
                 $second = intval($value);
                 break;
                 //				case 'T':
                 //					$date = date_parse($value);
                 //					$hour -= ($date['zone'] / 60);
                 //					break;
         }
     }
     KalturaLog::debug("gmmktime({$hour}, {$minute}, {$second}, {$month}, {$day}, {$year})");
     $ret = gmmktime($hour, $minute, $second, $month, $day, $year);
     if ($ret) {
         KalturaLog::debug("Formated Date [{$ret}] " . date('Y-m-d\\TH:i:s', $ret));
         return $ret;
     }
     KalturaLog::debug("Formated Date [null]");
     return null;
 }
 function date_create_from_format($format, $value)
 {
     $format = str_replace(array('Y', 'm', 'd', 'H', 'i', 'a'), array('%Y', '%m', '%d', '%I', '%M', '%p'), $format);
     $ugly = strptime($value, $format);
     $ymd = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $ugly['tm_year'] + 1900, $ugly['tm_mon'] + 1, $ugly['tm_mday'], $ugly['tm_hour'], $ugly['tm_min'], $ugly['tm_sec']);
     $d = new DateTime($ymd);
     return $d;
 }
예제 #13
0
function trendoo_date_to_unix_timestamp($trendoo_date)
{
    $res = strptime($trendoo_date, TRENDOO_DATE_TIME_FORMAT);
    if ($res != false) {
        return mktime($res['tm_hour'], $res['tm_min'], $res['tm_sec'], $res['tm_mon'], $res['tm_mday'], $res['tm_year'] + 1900);
    } else {
        return null;
    }
}
예제 #14
0
function strToTimestamp2($date, $format)
{
    $decoded_date = strptime($date, dateFormatToStrftime($format));
    if ($decoded_date !== false) {
        return mktime($decoded_date['tm_hour'], $decoded_date['tm_min'], $decoded_date['tm_sec'], $decoded_date['tm_mon'] + 1, $decoded_date['tm_mday'], $decoded_date['tm_year'] + 1900);
    } else {
        return 0;
    }
}
예제 #15
0
 public function parse($str)
 {
     //cut [ and ] if needed
     $str = trim($str, '[]');
     $time = strptime($str, $this->format);
     if (!$time) {
         return false;
     }
     return mktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon'] + 1, $time['tm_mday'], $time['tm_year'] + 1900);
 }
예제 #16
0
 /**
  * Método de apoio, criado pois o php 5.2 não possui todos os metodos que são precisos
  * @param string $dformat O formato do DateTime
  * @param string $dvalue O tempo
  * @return \DateTime
  */
 public static function createFromFormat($dformat, $dvalue)
 {
     $schedule = $dvalue;
     $schedule_format = str_replace(array('Y', 'm', 'd', 'H', 'i', 'a'), array('%Y', '%m', '%d', '%I', '%M', '%p'), $dformat);
     // %Y, %m and %d correspond to date()'s Y m and d.
     // %I corresponds to H, %M to i and %p to a
     $ugly = strptime($schedule, $schedule_format);
     $ymd = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $ugly['tm_year'] + 1900, $ugly['tm_mon'] + 1, $ugly['tm_mday'], $ugly['tm_hour'], $ugly['tm_min'], $ugly['tm_sec']);
     $new_schedule = new DateTime($ymd);
     return $new_schedule;
 }
예제 #17
0
파일: Dates.php 프로젝트: dxw/php-missing
 public static function parse($str)
 {
     $formats = array('%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S', '%Y-%m-%dT%H:%M', '%Y-%m-%d %H:%M', '%Y-%m-%d');
     foreach ($formats as $format) {
         $time = strptime($str, $format);
         if ($time !== false) {
             return [self::parseStrptime($time), null];
         }
     }
     return [null, true];
 }
예제 #18
0
 /**
  * Sets control's value.
  * @param  string
  * @return void
  */
 public function setValue($value)
 {
     if (!is_array($value)) {
         $value = strptime($value, $this->parseValueFormat());
         // '%Y-%m-%d %H:%M'
     }
     if (isset($value['tm_year'])) {
         $value['tm_year'] += 1900;
     }
     return parent::setValue($value);
 }
예제 #19
0
function check_date($date, $err_msg)
{
    if ($date == null) {
        return true;
    }
    $result = strptime($date, 'Y-m-d');
    if ($date == false) {
        return check_function_on_error($err_msg);
    }
    return true;
}
예제 #20
0
/**
 * check datetime string if valid. see xapp_is_date for more explanations since
 * the this function does the same only with datetime values
 *
 * @param null|string $datetime expects datetime string to be checked for validity
 * @param bool $strict expects boolean value to check against xapp config datetime format
 * @return bool
 */
function xapp_is_datetime($datetime = null, $strict = false)
{
    if ($datetime !== null) {
        if ((bool) $strict) {
            return (bool) @strptime($datetime, xapp_conf(XAPP_CONF_DATETIME_FORMAT));
        } else {
            return (bool) @strtotime((string) $datetime);
        }
    }
    return false;
}
예제 #21
0
 /**
  * Converts date + time as given in the scraped HTML into a unix timestamp
  *
  * @param string $dateraw
  * @param string $daterawformat not used here
  * @return int
  */
 protected function convertDate($dateraw, $daterawformat = NULL)
 {
     $trimmed_dateraw = trim($dateraw);
     $unix_timestamp = 0;
     //defaults to 1970...
     if (preg_match('/^Stand:\\s+(.*)\\s/', $trimmed_dateraw, $extracted_date) === 1) {
         $formatted_dateraw = strptime($extracted_date[1], "%d.%m.%Y %H:%M");
         $unix_timestamp = mktime($formatted_dateraw['tm_hour'], $formatted_dateraw['tm_min'], 0, $formatted_dateraw['tm_mon'] + 1, $formatted_dateraw['tm_mday'], $formatted_dateraw['tm_year'] + 1900);
     }
     return $unix_timestamp;
 }
예제 #22
0
 /**
  * Returns TRUE if submitted value validates according to rule
  *
  * @return boolean
  * @see tx_form_System_Validate_Interface::isValid()
  */
 public function isValid()
 {
     if ($this->requestHandler->has($this->fieldName)) {
         $value = $this->requestHandler->getByMethod($this->fieldName);
         $parsedDate = strptime($value, $this->format);
         $parsedDateYear = $parsedDate['tm_year'] + 1900;
         $parsedDateMonth = $parsedDate['tm_mon'] + 1;
         $parsedDateDay = $parsedDate['tm_mday'];
         return checkdate($parsedDateMonth, $parsedDateDay, $parsedDateYear);
     }
     return TRUE;
 }
예제 #23
0
function check_rfc822_date($date)
{
    if (trim($date) != "") {
        $_date = preg_replace('/ (GMT|\\+0000)$/', '', $date);
        // Unfortunately strptime() does not exist on Windows. date(DATE_RFC822), strftime()
        $checked_date = function_exists('strptime') ? strptime('%a, %d %b %y %H:%M:%S %Z', $_date) : strtotime($_date);
        if (false === $checked_date) {
            return false;
        }
    }
    return true;
}
예제 #24
0
 public function parse($value, $type, $format = NULL)
 {
     $result = strptime($value, $format ?: $this->formats[$type]);
     if ($result === FALSE) {
         return NULL;
     }
     $result = mktime($result['tm_hour'], $result['tm_min'], min(59, $result['tm_sec']), $result['tm_month'] + 1, $result['tm_day'], $result['tm_year'] + 1900);
     if ($result === FALSE) {
         return NULL;
     }
     return \DateTime::createFromFormat('U', $result);
 }
예제 #25
0
 /**
  * Convert the date to a more useful format.
  *
  * @param string $date Date string.
  *
  * @return string Converted date
  */
 protected function dateConvert($date)
 {
     if (strptime($date, "%d.%m.%Y %H:%M:%S") !== false) {
         $arr = strptime($date, "%d.%m.%Y %H:%M:%S");
         $time = \DateUtil::buildDatetime($arr['tm_year'], $arr['tm_mon'], $arr['tm_monday'], $arr['tm_hour'], $arr['tm_min'], $arr['tm_sec']);
     } elseif (is_numeric($date)) {
         $time = \DateUtil::getDatetime($date);
     } else {
         $time = str_replace('_', ' ', $date);
     }
     return $time;
 }
예제 #26
0
 function isValid($date)
 {
     $parsed_date = strptime($date, $this->format);
     if ($parsed_date === false) {
         return false;
     }
     $parsed_date['tm_year'] += 1900;
     $parsed_date['tm_mon'] += 1;
     $timestamp = mktime(0, 0, 0, $parsed_date['tm_mon'], $parsed_date['tm_mday'], $parsed_date['tm_year']);
     $date_to_compare = strftime($this->format, $timestamp);
     return isset($parsed_date['tm_year']) && isset($parsed_date['tm_mon']) && isset($parsed_date['tm_mday']) && $date == $date_to_compare;
 }
예제 #27
0
 public static function parseDate($strDate, $strFormat)
 {
     /* This method parses a date/time value using a defined format. 
      * It returns a timestamp that can be used with strftime.
      */
     $arrDate = function_exists("strptime") ? strptime($strDate, $strFormat) : self::__strptime($strDate, $strFormat);
     $hour = $arrDate['tm_hour'] > 23 || $arrDate['tm_hour'] < 0 ? 0 : $arrDate['tm_hour'];
     $minute = $arrDate['tm_min'] > 59 || $arrDate['tm_min'] < 0 ? 0 : $arrDate['tm_min'];
     $second = $arrDate['tm_sec'] > 61 || $arrDate['tm_sec'] < 0 ? 0 : $arrDate['tm_sec'];
     $timestamp = mktime($hour, $minute, $second, $arrDate['tm_mon'] + 1, $arrDate['tm_mday'], $arrDate['tm_year'] + 1900);
     return $timestamp;
 }
예제 #28
0
 function index($category_id = 0, $start_date = NULL, $end_date = NULL)
 {
     $placemarks = "";
     $style_map = "";
     // Do we have a category id to filter by?
     if (is_numeric($category_id) && $category_id != 0) {
         $filter = 'incident.incident_active = 1 AND incident_category.category_id = ' . $category_id;
         $filter_cat = 'category_visible = 1 AND id = ' . $category_id;
     } else {
         $filter = 'incident.incident_active = 1';
         $filter_cat = 'category_visible = 1';
         $category_id = 0;
     }
     // Do we have dates to filter by?
     if (strptime($start_date, '%G-%m-%d') && strptime($end_date, '%G-%m-%d')) {
         $filter .= ' AND incident_date BETWEEN \'' . $start_date . ' 00:00:00\' AND  \'' . $end_date . ' 23:59:59\' ';
     }
     // Retrieve individual markers
     foreach (ORM::factory('incident')->join('incident_category', 'incident.id', 'incident_category.incident_id', 'INNER')->select('incident.*')->where($filter)->orderby('incident.incident_dateadd', 'desc')->find_all() as $marker) {
         $placemarks .= "<Placemark>\n";
         $placemarks .= "<name>" . htmlentities("<a href=\"" . url::base() . "reports/view/" . $marker->id . "\">" . $marker->incident_title . "</a>") . "</name>\n";
         $placemarks .= "<description>" . htmlentities($marker->incident_description) . "</description>\n";
         $placemarks .= "<Point>\n";
         $placemarks .= "<coordinates>" . htmlentities($marker->location->longitude . "," . $marker->location->latitude) . "</coordinates>\n";
         $placemarks .= "</Point>\n";
         if ($category_id != 0) {
             $placemarks .= "<styleUrl>#" . $category_id . "</styleUrl>\n";
         } else {
             foreach ($marker->incident_category as $category) {
                 $placemarks .= "<styleUrl>#" . $category->category->id . "</styleUrl>\n";
                 break 1;
             }
         }
         $placemarks .= "<TimeStamp>\n";
         $placemarks .= "<when>" . date('Y-m-d', strtotime($marker->incident_date)) . "T" . date('H:i:s', strtotime($marker->incident_date)) . "-05:00" . "</when>\n";
         $placemarks .= "</TimeStamp>\n";
         $placemarks .= "</Placemark>\n";
     }
     // Create Stylemap From individual categories
     foreach (ORM::factory('category')->where($filter_cat)->orderby('category_title', 'asc')->find_all() as $category) {
         $style_map .= "<Style id=\"" . $category->id . "\">\n";
         $style_map .= "<IconStyle>\n";
         $style_map .= "<scale>0.5</scale>\n";
         $style_map .= "<Icon>\n";
         $style_map .= "<href>" . htmlentities(url::base() . "swatch/?c=" . $category->category_color . "&w=16&h=16&.png") . "</href>\n";
         $style_map .= "</Icon>\n";
         $style_map .= "</IconStyle>\n";
         $style_map .= "</Style>\n";
     }
     $this->template->placemarks = $placemarks;
     $this->template->style_map = $style_map;
 }
예제 #29
0
 public function clean($value)
 {
     parent::clean($value);
     foreach ($this->input_formats as $format) {
         if (false !== ($date = strptime($value, $format))) {
             $day = str_pad($date['tm_mday'], 2, '0', STR_PAD_LEFT);
             $month = str_pad($date['tm_mon'] + 1, 2, '0', STR_PAD_LEFT);
             $year = str_pad($date['tm_year'] + 1900, 4, '0', STR_PAD_LEFT);
             return $year . '-' . $month . '-' . $day;
         }
     }
     throw new Pluf_Form_Invalid(__('Enter a valid date.'));
 }
예제 #30
0
 static function set_auto_date($item)
 {
     if (!$item->is_album() && !$item->captured) {
         $base_name = str_ireplace(array(".flv", ".jpg", ".gif"), "", $item->name);
         $date_format = module::get_var("auto_date", "template");
         $time = strptime($base_name, $date_format);
         if ($time) {
             $item->captured = mktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon'] + 1, $time['tm_mday'], $time['tm_year'] + 1900);
             $item->save();
         }
     }
     return;
 }