Example #1
0
 /**
  * Returns pretty weekday name.
  * @param null|int $timestamp If not set, current timestamp will be used.
  * @param bool $useAlternateNames Whether to use today, tomorrow names.
  * @return string
  */
 public static function getPrettyWeekdayName($timestamp = null, $useAlternateNames = false)
 {
     if ($timestamp === null) {
         $timestamp = time();
     }
     if ($useAlternateNames) {
         $date1 = new \DateTime(TimeHelper::getDate());
         $date2 = new \DateTime(TimeHelper::getDate($timestamp));
         $diff = $date2->diff($date1)->format("%a");
         if ($diff == 0) {
             return \Yii::t('mgcode/helpers', 'Today');
         } else {
             if ($diff == 1) {
                 return \Yii::t('mgcode/helpers', 'Tomorrow');
             }
         }
     }
     $day = date('N', $timestamp);
     $translations = [1 => \Yii::t('mgcode/helpers', 'Monday'), 2 => \Yii::t('mgcode/helpers', 'Tuesday'), 3 => \Yii::t('mgcode/helpers', 'Wednesday'), 4 => \Yii::t('mgcode/helpers', 'Thursday'), 5 => \Yii::t('mgcode/helpers', 'Friday'), 6 => \Yii::t('mgcode/helpers', 'Saturday'), 7 => \Yii::t('mgcode/helpers', 'Sunday')];
     return $translations[$day];
 }