]> git.mxchange.org Git - friendica.git/blobdiff - include/datetime.php
Merge pull request #3333 from Rudloff/feature/theme-color
[friendica.git] / include / datetime.php
index a17c405dc365ea391d3ada2fd0c3f16d82f3e855..287e9a2d84a232bf666b54d38f66ab55c3c5cb1b 100644 (file)
@@ -4,6 +4,7 @@
  * @brief Some functions for date and time related tasks.
  */
 
+use \Friendica\Core\Config;
 
 /**
  * @brief Two-level sort for timezones.
@@ -125,7 +126,7 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
        // add 32 days so that we at least get year 00, and then hack around the fact that
        // months and days always start with 1.
 
-       if(substr($s,0,10) == '0000-00-00') {
+       if(substr($s,0,10) <= '0001-01-01') {
                $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC'));
                return str_replace('1','0',$d->format($fmt));
        }
@@ -170,7 +171,7 @@ function dob($dob) {
        $f = get_config('system','birthday_input_format');
        if(! $f)
                $f = 'ymd';
-       if($dob === '0000-00-00')
+       if($dob <= '0001-01-01')
                $value = '';
        else
                $value = (($year) ? datetime_convert('UTC','UTC',$dob,'Y-m-d') : datetime_convert('UTC','UTC',$dob,'m-d'));
@@ -188,7 +189,7 @@ function dob($dob) {
                )
        ));
 
-//     if ($dob && $dob != '0000-00-00')
+//     if ($dob && $dob > '0001-01-01')
 //             $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob');
 //     else
 //             $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),false,'dob');
@@ -271,8 +272,9 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke
        $lang = substr(get_browser_language(), 0, 2);
 
        // Check if the detected language is supported by the picker
-       if (!in_array($lang, array("ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr", "it", "da", "no", "ja", "vi", "sl", "cs", "hu")))
-               $lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
+       if (!in_array($lang, array("ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr", "it", "da", "no", "ja", "vi", "sl", "cs", "hu"))) {
+               $lang = Config::get('system', 'language', 'en');
+       }
 
        $o = '';
        $dateformat = '';
@@ -337,7 +339,7 @@ function relative_date($posted_date, $format = null) {
 
        $abs = strtotime($localtime);
 
-       if (is_null($posted_date) || $posted_date === '0000-00-00 00:00:00' || $abs === False) {
+       if (is_null($posted_date) || $posted_date <= NULL_DATE || $abs === False) {
                 return t('never');
        }
 
@@ -551,7 +553,7 @@ function update_contact_birthdays() {
        // This only handles foreign or alien networks where a birthday has been provided.
        // In-network birthdays are handled within local_delivery
 
-       $r = q("SELECT * FROM contact WHERE `bd` != '' AND `bd` != '0000-00-00' AND SUBSTRING(`bd`,1,4) != `bdyear` ");
+       $r = q("SELECT * FROM contact WHERE `bd` != '' AND `bd` > '0001-01-01' AND SUBSTRING(`bd`,1,4) != `bdyear` ");
        if (dbm::is_result($r)) {
                foreach ($r as $rr) {
 
@@ -569,6 +571,17 @@ function update_contact_birthdays() {
                         *
                         */
 
+                       // Check for duplicates
+                       $s = q("SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1",
+                               intval($rr['uid']),
+                               intval($rr['id']),
+                               dbesc(datetime_convert('UTC','UTC', $nextbd)),
+                               dbesc('birthday'));
+
+                       if (dbm::is_result($s)) {
+                               continue;
+                       }
+
                        $bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
                        $bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;