コード例 #1
0
ファイル: age.php プロジェクト: Ermile/Saloos
 /**
  * get birthday and return age
  *
  * @param      <type>  $_brithday  The brithday
  */
 public static function get_age($_brithday)
 {
     if ($_brithday == null) {
         return null;
     }
     $brith_year = date("Y", strtotime($_brithday));
     $brith_month = date("m", strtotime($_brithday));
     $brith_day = date("d", strtotime($_brithday));
     // to convert the jalali date to gregorian date
     if (intval($brith_year) > 1300 && intval($brith_year) < 1400) {
         list($brith_year, $brith_month, $brith_day) = \lib\utility\jdate::toGregorian($brith_year, $brith_month, $brith_day);
         if ($brith_month < 10) {
             $brith_month = "0" . $brith_month;
         }
         if ($brith_day < 10) {
             $brith_day = "0" . $brith_day;
         }
     }
     // get date diff
     $date1 = new \DateTime($brith_year . $brith_month . $brith_day);
     $date2 = new \DateTime("now");
     $age = $date1->diff($date2);
     $age = $age->y;
     return $age;
 }
コード例 #2
0
ファイル: twigAddons.php プロジェクト: Ermile/Saloos
 /**
  * twig custom filter for convert date to best type of showing on each language
  * tdate means translated date
  */
 public function twig_filter_tdate()
 {
     return new \Twig_SimpleFilter('tdate', function ($_string, $_format = "Y/m/d", $_convert = true) {
         $result = $_string;
         if ($this->data->site['currentlang'] == 'fa') {
             $result = \lib\utility\jdate::date($_format, $_string, $_convert);
         } else {
             $result = date($_format, strtotime($_string));
         }
         return $result;
     });
 }
コード例 #3
0
ファイル: utility.php プロジェクト: Ermile/Saloos
 /**
  * check saloos language and if needed convert to persian date
  * else show default date
  * @param  [type] $_date [description]
  * @return [type]        [description]
  */
 public static function date($_format, $_stamp = false, $_type = false, $_persianChar = true)
 {
     $result = null;
     if (strlen($_stamp) < 2) {
         $_stamp = false;
     }
     // get target language
     if ($_type === 'default') {
         $_type = substr(\lib\router::get_storage('defaultLanguage'), 0, 2);
     } elseif ($_type === 'current') {
         $_type = substr(\lib\router::get_storage('language'), 0, 2);
     }
     // if need persian use it else use default date function
     if ($_type === true || $_type === 'fa') {
         $result = \lib\utility\jdate::date($_format, $_stamp, $_persianChar);
     } else {
         if ($_stamp) {
             $result = date($_format, $_stamp);
         } else {
             $result = date($_format);
         }
     }
     return $result;
 }
コード例 #4
0
ファイル: utility.php プロジェクト: evazzadeh/Saloos
 public static function humanTiming($_time, $_max = 'ultimate', $_format = "Y/m/d", $_lang = 'en')
 {
     // auto convert with strtotime function
     $_time = strtotime($_time);
     $time_diff = time() - $_time;
     // to get the time since that moment
     $tokens = array(31536000 => T_('year'), 2592000 => T_('month'), 604800 => T_('week'), 86400 => T_('day'), 3600 => T_('hour'), 60 => T_('minute'), 1 => T_('second'));
     if ($time_diff < 10) {
         return T_('A few seconds ago');
     }
     $_max = array_search(T_($_max), $tokens);
     foreach ($tokens as $unit => $text) {
         if ($time_diff < $unit) {
             continue;
         }
         // if time diff less than user request change it to humansizing
         if ($time_diff < $_max || $_max == T_('ultimate')) {
             $numberOfUnits = floor($time_diff / $unit);
             return $numberOfUnits . ' ' . $text . ($numberOfUnits > 1 ? T_('s ') : ' ') . T_('ago');
         } else {
             if ($_lang == 'fa') {
                 return \lib\utility\jdate::date($_format, $_time);
             } else {
                 return date($_format, $_time);
             }
         }
     }
 }
コード例 #5
0
ファイル: twigAddons.php プロジェクト: evazzadeh/Saloos
 /**
  * twig custom filter for convert date to jalai with custom format like php date func format
  */
 public function twig_filter_jdate()
 {
     return new \Twig_SimpleFilter('jdate', function ($_string, $_format = "Y/m/d") {
         return \lib\utility\jdate::date($_format, $_string);
     });
 }