Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.

Commit 6d07871

Browse files
committed
Add 'timeAhead' method
1 parent 686e193 commit 6d07871

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Softlabs/Date/Date.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,34 @@ public function timeAgo($date, $suffix='ago')
140140
return "$difference $periods[$j] $suffix";
141141
}
142142

143+
/**
144+
* Retrieves how far ahead a specific time is from now
145+
*
146+
* @param string $date
147+
* @return string
148+
*/
149+
public function timeAhead($date)
150+
{
151+
$date = strtotime($date);
152+
153+
if ($date >= strtotime('today 00:00') and $date <= strtotime('tomorrow 00:00'))
154+
{
155+
return 'Today at ' . date('g:ia', $date);
156+
}
157+
elseif ($date >= strtotime('tomorrow 00:00') and $date <= strtotime('+2 day 00:00'))
158+
{
159+
return 'Tomorrow at ' . date('g:ia', $date);
160+
}
161+
elseif ($date >= strtotime('+2 day 00:00') and $date <= strtotime('+6 day 00:00'))
162+
{
163+
return date('l \\a\\t g:ia', $date);
164+
}
165+
else
166+
{
167+
return date('M j, Y g:ia', $date);
168+
}
169+
}
170+
143171
/**
144172
* Displays how long ago a time was or an alternative string.
145173
*

0 commit comments

Comments
 (0)