Newer
Older
case 'short':
return Format::date($this->date, $this->fromdb, false, $this->timezone, $this->user);
case 'long':
return Format::datetime($this->date, $this->fromdb, $this->timezone, $this->user);
case 'time':
return Format::time($this->date, $this->fromdb, false, $this->timezone, $this->user);
case 'full':
return Format::daydatetime($this->date, $this->fromdb, $this->timezone, $this->user);
}
}
function __toString() {
return $this->asVar() ?: '';
}
static function getVarScope() {
return array(
'full' => 'Expanded date, e.g. day, month dd, yyyy',
'long' => 'Date and time, e.g. d/m/yyyy hh:mm',
'short' => 'Date only, e.g. d/m/yyyy',
'time' => 'Time only, e.g. hh:mm',
);
}
}
class FormattedDate
extends FormattedLocalDate {
function asVar() {
return $this->getVar('system')->asVar();
}
function __toString() {
global $cfg;
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
$timezone = new DatetimeZone($this->timezone ?:
$cfg->getTimezone());
$options = array(
'timezone' => $timezone->getName(),
'fromdb' => $this->fromdb,
'format' => $this->format
);
$val = (string) new FormattedLocalDate($this->date, $options);
if ($this->timezone && $this->format == 'long') {
try {
$this->datetime->setTimezone($timezone);
$val = sprintf('%s %s',
$val, $this->datetime->format('T'));
} catch(Exception $ex) {
// ignore
}
}
return $val;
function getVar($what, $context=null) {
if ($rv = parent::getVar($what, $context))
return $rv;
switch ($what) {
case 'user':
// Fetch $recipient from the context and find that user's time zone
if ($context && ($recipient = $context->getObj('recipient'))) {
$options = array(
'timezone' => $recipient->getTimezone() ?: $cfg->getDefaultTimezone(),
'user' => $recipient
);
return new FormattedLocalDate($this->date, $options);
// Don't resolve the variable until correspondance is sent out
return false;
return new FormattedLocalDate($this->date, array(
'timezone' => $cfg->getDefaultTimezone()
)
);
}
}
function getHumanize() {
return Format::relativeTime(Misc::db2gmtime($this->date));
}
static function getVarScope() {
return parent::getVarScope() + array(
'humanize' => 'Humanized time, e.g. about an hour ago',
'user' => array(
'class' => 'FormattedLocalDate', 'desc' => "Localize to recipient's time zone and locale"),
'system' => array(
'class' => 'FormattedLocalDate', 'desc' => 'Localize to system default time zone'),
);
}