Merge pull request #6896 from nextcloud/12-timespan-check
[12] timespan check
This commit is contained in:
commit
aaad2ab6b0
|
@ -159,18 +159,42 @@ class DateTimeFormatter implements \OCP\IDateTimeFormatter {
|
||||||
if ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 0) {
|
if ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 0) {
|
||||||
return (string) $l->t('today');
|
return (string) $l->t('today');
|
||||||
} else if ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 1) {
|
} else if ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 1) {
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->t('tomorrow');
|
||||||
|
} else {
|
||||||
return (string) $l->t('yesterday');
|
return (string) $l->t('yesterday');
|
||||||
|
}
|
||||||
} else if ($dateInterval->y == 0 && $dateInterval->m == 0) {
|
} else if ($dateInterval->y == 0 && $dateInterval->m == 0) {
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->n('in %n day', 'in %n days', $dateInterval->d);
|
||||||
|
} else {
|
||||||
return (string) $l->n('%n day ago', '%n days ago', $dateInterval->d);
|
return (string) $l->n('%n day ago', '%n days ago', $dateInterval->d);
|
||||||
|
}
|
||||||
} else if ($dateInterval->y == 0 && $dateInterval->m == 1) {
|
} else if ($dateInterval->y == 0 && $dateInterval->m == 1) {
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->t('next month');
|
||||||
|
} else {
|
||||||
return (string) $l->t('last month');
|
return (string) $l->t('last month');
|
||||||
|
}
|
||||||
} else if ($dateInterval->y == 0) {
|
} else if ($dateInterval->y == 0) {
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->n('in %n month', 'in %n months', $dateInterval->m);
|
||||||
|
} else {
|
||||||
return (string) $l->n('%n month ago', '%n months ago', $dateInterval->m);
|
return (string) $l->n('%n month ago', '%n months ago', $dateInterval->m);
|
||||||
|
}
|
||||||
} else if ($dateInterval->y == 1) {
|
} else if ($dateInterval->y == 1) {
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->t('next year');
|
||||||
|
} else {
|
||||||
return (string) $l->t('last year');
|
return (string) $l->t('last year');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->n('in %n year', 'in %n years', $dateInterval->y);
|
||||||
|
} else {
|
||||||
return (string) $l->n('%n year ago', '%n years ago', $dateInterval->y);
|
return (string) $l->n('%n year ago', '%n years ago', $dateInterval->y);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the time of the given timestamp
|
* Formats the time of the given timestamp
|
||||||
|
@ -219,12 +243,24 @@ class DateTimeFormatter implements \OCP\IDateTimeFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($diff->h > 0) {
|
if ($diff->h > 0) {
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->n('in %n hour', 'in %n hours', $diff->h);
|
||||||
|
} else {
|
||||||
return (string) $l->n('%n hour ago', '%n hours ago', $diff->h);
|
return (string) $l->n('%n hour ago', '%n hours ago', $diff->h);
|
||||||
|
}
|
||||||
} else if ($diff->i > 0) {
|
} else if ($diff->i > 0) {
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->n('in %n minute', 'in %n minutes', $diff->i);
|
||||||
|
} else {
|
||||||
return (string) $l->n('%n minute ago', '%n minutes ago', $diff->i);
|
return (string) $l->n('%n minute ago', '%n minutes ago', $diff->i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ($timestamp > $baseTimestamp) {
|
||||||
|
return (string) $l->t('in a few seconds');
|
||||||
|
} else {
|
||||||
return (string) $l->t('seconds ago');
|
return (string) $l->t('seconds ago');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the date and time of the given timestamp
|
* Formats the date and time of the given timestamp
|
||||||
|
|
|
@ -46,10 +46,13 @@ class DateTimeFormatterTest extends TestCase {
|
||||||
$deL10N = \OC::$server->getL10N('lib', 'de');
|
$deL10N = \OC::$server->getL10N('lib', 'de');
|
||||||
return array(
|
return array(
|
||||||
array('seconds ago', $time, $time),
|
array('seconds ago', $time, $time),
|
||||||
|
array('in a few seconds', $time + 5 , $time),
|
||||||
array('1 minute ago', $this->getTimestampAgo($time, 30, 1), $time),
|
array('1 minute ago', $this->getTimestampAgo($time, 30, 1), $time),
|
||||||
array('15 minutes ago', $this->getTimestampAgo($time, 30, 15), $time),
|
array('15 minutes ago', $this->getTimestampAgo($time, 30, 15), $time),
|
||||||
|
array('in 15 minutes', $time, $this->getTimestampAgo($time, 30, 15)),
|
||||||
array('1 hour ago', $this->getTimestampAgo($time, 30, 15, 1), $time),
|
array('1 hour ago', $this->getTimestampAgo($time, 30, 15, 1), $time),
|
||||||
array('3 hours ago', $this->getTimestampAgo($time, 30, 15, 3), $time),
|
array('3 hours ago', $this->getTimestampAgo($time, 30, 15, 3), $time),
|
||||||
|
array('in 3 hours', $time, $this->getTimestampAgo($time, 30, 15, 3)),
|
||||||
array('4 days ago', $this->getTimestampAgo($time, 30, 15, 3, 4), $time),
|
array('4 days ago', $this->getTimestampAgo($time, 30, 15, 3, 4), $time),
|
||||||
|
|
||||||
array('seconds ago', new \DateTime('Wed, 02 Oct 2013 23:59:58 +0000'), new \DateTime('Wed, 02 Oct 2013 23:59:59 +0000')),
|
array('seconds ago', new \DateTime('Wed, 02 Oct 2013 23:59:58 +0000'), new \DateTime('Wed, 02 Oct 2013 23:59:59 +0000')),
|
||||||
|
@ -86,9 +89,15 @@ class DateTimeFormatterTest extends TestCase {
|
||||||
// Normal testing
|
// Normal testing
|
||||||
array('today', $this->getTimestampAgo($time, 30, 15), $time),
|
array('today', $this->getTimestampAgo($time, 30, 15), $time),
|
||||||
array('yesterday', $this->getTimestampAgo($time, 0, 0, 0, 1), $time),
|
array('yesterday', $this->getTimestampAgo($time, 0, 0, 0, 1), $time),
|
||||||
|
array('tomorrow', $time, $this->getTimestampAgo($time, 0, 0, 0, 1)),
|
||||||
array('4 days ago', $this->getTimestampAgo($time, 0, 0, 0, 4), $time),
|
array('4 days ago', $this->getTimestampAgo($time, 0, 0, 0, 4), $time),
|
||||||
|
array('in 4 days', $time, $this->getTimestampAgo($time, 0, 0, 0, 4)),
|
||||||
array('5 months ago', $this->getTimestampAgo($time, 0, 0, 0, 155), $time),
|
array('5 months ago', $this->getTimestampAgo($time, 0, 0, 0, 155), $time),
|
||||||
|
array('next month', $time, $this->getTimestampAgo($time, 0, 0, 0, 32)),
|
||||||
|
array('in 5 months', $time, $this->getTimestampAgo($time, 0, 0, 0, 155)),
|
||||||
array('2 years ago', $this->getTimestampAgo($time, 0, 0, 0, 0, 2), $time),
|
array('2 years ago', $this->getTimestampAgo($time, 0, 0, 0, 0, 2), $time),
|
||||||
|
array('next year', $time, $this->getTimestampAgo($time, 0, 0, 0, 0, 1)),
|
||||||
|
array('in 2 years', $time, $this->getTimestampAgo($time, 0, 0, 0, 0, 2)),
|
||||||
|
|
||||||
// Test with compare timestamp
|
// Test with compare timestamp
|
||||||
array('today', $this->getTimestampAgo($time, 0, 0, 0, 0, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)),
|
array('today', $this->getTimestampAgo($time, 0, 0, 0, 0, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)),
|
||||||
|
|
Loading…
Reference in New Issue