Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
public function format($time, $settings = array())
{
$this->setProperties($time, $settings); if ($this->Time->isToday($time)){
return 'Oggi'.$this->settings['hoursMinutes'];
}
if ($this->Time->wasYesterday($time)){
return 'Ieri'.$this->settings['hoursMinutes'];
}
if ($this->Time->isThisMonth($time)){
return $this->settings['dayLetters'].' '.$this->settings['dayNumbers']. ' ' .$this->settings['monthLetters'].$this->settings['hoursMinutesPast'];
}
if ($this->Time->isThisYear($time)){
return $this->settings['dayNumbers']. ' '.$this->settings['monthLetters'];
}
return $this->settings['dayNumbers'].'/'.$this->settings['monthNumbers'].'/'.$this->settings['year'];
}
public function timeAgo($time, $settings = array())
{
$this->setProperties($time, $settings);
if ($this->Time->isFuture($time)){
return $this->Time->format('d/m/Y', $time);
}
if ($this->Time->isToday($time)){
if (date('H') == $this->settings['hours']){
$minutesAgo = date('i') - $this->settings['minutes'];
return $minutesAgo . ' minuti fa';
}
$hourAgo = date('H') - $this->settings['hours'];
if ($hourAgo <= 6){
return $hourAgo . ' ore fa';
}
return 'Oggi'.$this->settings['hoursMinutes'];
}
return $this->format($time, $settings);
}
public function timeLeft($time, $settings = array())
{
$this->setProperties($time, $settings);
if ($this->Time->isTomorrow($time)){
return 'Domani'.$this->settings['hoursMinutes'];
}
if ($this->Time->isToday($time)){
return 'Oggi'.$this->settings['hoursMinutes'];
}
if (!$this->Time->isFuture($time)) return $this->Time->format('d/m/Y', $time);
if ($this->Time->isThisMonth($time)){
$daysLeft = $this->settings['dayNumbers'] - date('d');
return 'Tra '.$daysLeft.' giorni'.$this->settings['hoursMinutes'];
}
return $this->settings['dayNumbers'].'/'.$this->settings['monthNumbers'].'/'.$this->settings['year'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.