Permalink
Browse files

Page::dateFromDateParse

Summary:
Allow to extract a date using date_parse

We use this method for Chroniques Automatiques,
it would also be useful for Le Parisien metatag.

Test Plan: Tested for D720

Reviewers: dereckson

Differential Revision: https://devcentral.nasqueron.org/D722
  • Loading branch information...
dereckson committed Nov 16, 2016
1 parent 8f2a1d0 commit 218ddcdbbe72025de4749ab2a7ce825fdc1f0318
Showing with 18 additions and 7 deletions.
  1. +17 −0 page.php
  2. +1 −7 pages/leschroniquesautomatiques.php
@@ -357,6 +357,23 @@ static function curl_download ($url, $agent = '') {
/// DATES
///
/**
* @param string $toParse The date to parse
* @param string $tz The timezone to use [optional]
*/
function dateFromDateParse ($toParse, $tz = 'Europe/Paris') {
$old_tz = date_default_timezone_get();
date_default_timezone_set($tz);
$date = date_parse($toParse);
$this->yyyy = $date['year'];
$this->mm = $date['month'];
$this->dd = $date['day'];
$this->unixtime = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']);
date_default_timezone_set($old_tz);
}
function extractYYYYMMDDDateFromURL() {
$pattern = "@/([12][0-9]{3})\-([0-9]{2})\-([0-9]{2})/@";
if (preg_match($pattern, $this->url, $matches)) {
@@ -8,15 +8,9 @@ function analyse () {
//Hardcoded known info
$this->site = "Les Chroniques Automatiques";
$this->author = "Dat’";
$this->skipYMD = true;
//Gets date
$old_tz = date_default_timezone_get();
date_default_timezone_set('Europe/Paris');
$date = date_parse(trim(self::between('This entry was posted on', 'and is filed under')));
$this->unixtime = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']);
$this->date = strftime(LONG_DATE_FORMAT, $this->unixtime);
$new_tz = date_default_timezone_set($old_tz);
$this->dateFromDateParse(trim(self::between('This entry was posted on', 'and is filed under')));
}
function get_title () {

0 comments on commit 218ddcd

Please sign in to comment.