Skip to content

Commit 568c926

Browse files
update time class
1 parent 144e9e6 commit 568c926

File tree

6 files changed

+117
-143
lines changed

6 files changed

+117
-143
lines changed

Capsule/TimeHelper.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
namespace Tamedevelopers\Support\Capsule;
66

7-
use DateTime;
87
use Tamedevelopers\Support\Country;
98

10-
119
class TimeHelper {
12-
1310

1411
/**
1512
* startDate
@@ -48,27 +45,20 @@ public function __construct($startDate = null, $endDate = null, string $format =
4845
}
4946

5047
/**
51-
* get
48+
* format
5249
*
5350
* @param bool $start Whether to return the start date (true) or the end date (false).
5451
* @param bool $year Whether to include the year in the result.
5552
* @return string The formatted date or range.
5653
*/
57-
public function get($start = false, $year = false)
54+
public function format($start = false, $year = false)
5855
{
5956
// Ensure startDate and endDate are formatted
60-
$startFormatted = $this->startDate instanceof \DateTime && !empty($this->format)
61-
? $this->startDate->format($this->format)
62-
: $this->startDate;
63-
64-
$endFormatted = $this->endDate instanceof \DateTime && !empty($this->format)
65-
? $this->endDate->format($this->format)
66-
: $this->endDate;
57+
$startFormatted = $this->startDate->format($this->format);
58+
$endFormatted = $this->endDate->format($this->format);
6759

6860
// Get the year from the relevant date
69-
$yearValue = $start
70-
? ($this->startDate instanceof \DateTime ? $this->startDate->format('Y') : null)
71-
: ($this->endDate instanceof \DateTime ? $this->endDate->format('Y') : null);
61+
$yearValue = $start ? ($this->startDate->format('Y')) : ($this->endDate->format('Y'));
7262

7363
// Build the result
7464
if ($start) {

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ Support Package For PHP and Laravel
108108
* [subMonths](#subMonths)
109109
* [addYears](#addYears)
110110
* [subYears](#subYears)
111-
* [dateRange](#dateRange)
112111
* [greeting](#greeting)
113112
* [timeDiff](#timeDiff)
113+
* [dateRange](#dateRange)
114114
* [allTimezone](#allTimezone)
115115
* [setTimeZone](#setTimeZone)
116116
* [getTimeZone](#getTimeZone)
@@ -553,6 +553,30 @@ This will read the PDF to the browser
553553
$time = TameTime('now', 'Africa/Lagos');
554554
```
555555

556+
### dateRange
557+
- Build date range according to value given
558+
- Accepts (2) params `value and format`
559+
560+
```
561+
use Tamedevelopers\Support\Time;
562+
$time = new Time();
563+
564+
$time->dateRange('0-10', 'D, M j')
565+
// Output: returns class of Tamedevelopers\Support\Capsule\TimeHelper
566+
567+
To get the output, we need to call the TimeHelper format method
568+
The format() method takes two [optional] param. `start, year` as boolean
569+
570+
$time->dateRange('0-10', 'D, M j')
571+
->format(true, true)
572+
// Output: Thu, Jan 23 - Tue, Mar 4, 2025
573+
574+
575+
$time->dateRange('0-10', 'D, M j')
576+
->format()
577+
// Output: Tue, Mar 4
578+
```
579+
556580
### allTimezone
557581
```
558582
Time::allTimezone();

Tests/mail.php

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,18 @@
1515
'from_name' => 'Tame Developers',
1616
]);
1717

18-
19-
$time = TameTime('first day of December 2008');
20-
21-
22-
dd(
23-
$time->timeDifference(),
24-
$time->addDay(2000)->ago('date'),
25-
$time->subDay(10)->ago('date'),
26-
$time->ago(),
27-
$time->today()->format(),
28-
$time->now()->addMonth(1)->subDay(1)->format(),
29-
$time->yesterday()->toDateTimeString(),
30-
$time->format(null, 'first day of December 2008'),
31-
// $time->toJs(),
32-
);
33-
34-
35-
// $mailer->to('tamedevelopers@gmail.com, fredi.peter@gmail.com')
36-
// ->subject('New subject')
37-
// ->body('Hello this is a body text')
38-
// ->attach(base_path("thousand_units.png"), 'New Name')
39-
// ->send(function($response){
40-
// // dd(
41-
// // $response
42-
// // );
43-
// });
18+
$mailer->to('tamedevelopers@gmail.com')
19+
->subject('New subject')
20+
->body('Hello this is a body text')
21+
->attach(
22+
base_path("thousand_units.png"),
23+
'New Name'
24+
)
25+
->send(function($response){
26+
// dd(
27+
// $response
28+
// );
29+
});
4430

4531

4632

Tests/time.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
$time2 = Time::setTimezone('Atlantic/South_Georgia');
2727
$time3 = Time::setTimezone('Indian/Antananarivo');
28+
$time = TameTime('first day of December 2008');
2829

2930
dd(
3031
TameTime()->date('yesterday')->ago(),
@@ -40,12 +41,20 @@
4041

4142
$time3,
4243
$time3->greetings(),
43-
4444
Time::getGlobalTimeZone(),
4545

46-
TameTime()->dateRange('1-14')->get(false, true),
47-
TameTime()->dateRange('0-40')->get(true),
48-
46+
TameTime()->dateRange('1-14'),
47+
TameTime()->dateRange('0-40')->format(true, true),
4948
// Time::allTimezone(),
5049

50+
$time->timeDifference(),
51+
$time->addDay(2000)->ago('date'),
52+
$time->subDay(10)->ago('date'),
53+
$time->ago(),
54+
$time->date('last week monday')->ago(),
55+
$time->today()->format(),
56+
$time->now()->addMonth(1)->subDay(1)->format(),
57+
$time->yesterday()->toDateTimeString(),
58+
$time->format(null, 'first day of December 2008'),
59+
5160
);

0 commit comments

Comments
 (0)