Skip to content

Commit d3f2ce1

Browse files
Merge pull request #107 from TheDragonCode/1.x
Refactored `feeds.php` config and `DateTimeTransformer` timezone handling
2 parents 8e66489 + 98cbf30 commit d3f2ce1

File tree

2 files changed

+35
-44
lines changed

2 files changed

+35
-44
lines changed

config/feeds.php

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,45 @@
99
*
1010
* This file defines how feeds are generated and presented, including
1111
* formatting, persistence, scheduling, console UX and value transformers.
12-
* Adjust the options below or override them via environment variables.
12+
* Adjust the options below according to your application needs.
1313
*/
1414
return [
1515
/**
1616
* Pretty-print the generated feed output.
1717
*
1818
* When enabled, the resulting XML/JSON will include indentation and
19-
* human‑friendly formatting. Disable for slightly smaller payload size.
20-
*
21-
* Default: false
19+
* human‑friendly formatting. Disable to reduce payload size.
2220
*/
2321
'pretty' => (bool) env('FEED_PRETTY', false),
2422

2523
/**
26-
* Output format options.
24+
* Output date/time options.
2725
*/
28-
'formats' => [
26+
'date' => [
2927
/**
3028
* Date/time format used when serializing timestamps to feeds.
31-
* You may use any PHP date format constant, e.g. DATE_ATOM, DATE_RFC3339
32-
* or a custom PHP date() format string.
33-
*
34-
* Default: DATE_ATOM
29+
* Accepts any valid PHP date/time format string or constant.
3530
*/
36-
'date' => DATE_ATOM,
31+
'format' => DATE_ATOM,
32+
33+
/**
34+
* The timezone applied when formatting dates.
35+
*/
36+
'timezone' => env('FEED_TIMEZONE', 'UTC'),
3737
],
3838

3939
/**
40-
* Database table settings used by the package (e.g., for generation logs or state).
40+
* Database table settings used by the package (for logs or internal state).
4141
*/
4242
'table' => [
4343
/**
4444
* The database connection name to use.
45-
*
46-
* Should match a connection defined in config/database.php under
47-
* the "connections" array.
48-
*
49-
* Default: sqlite
45+
* Should match a connection defined in config/database.php.
5046
*/
5147
'connection' => env('DB_CONNECTION', 'sqlite'),
5248

5349
/**
5450
* The database table name used by the package.
55-
*
56-
* Default: feeds
5751
*/
5852
'table' => env('FEED_TABLE', 'feeds'),
5953
],
@@ -63,22 +57,14 @@
6357
*/
6458
'schedule' => [
6559
/**
66-
* Time To Live (in minutes) for the schedule lock or cache.
67-
*
68-
* Controls how frequently a scheduled job may be executed to avoid
69-
* overlapping or excessively frequent runs.
70-
*
71-
* Default: 1440 (24 hours)
60+
* Time-to-live (in minutes) for the schedule lock or cache.
61+
* Helps prevent overlapping or excessively frequent runs.
7262
*/
7363
'ttl' => (int) env('FEED_SCHEDULE_TTL', 1440),
7464

7565
/**
7666
* Run scheduled jobs in the background.
77-
*
78-
* When true, tasks will be dispatched to run asynchronously so they do
79-
* not block the current process. Set to false to run in the foreground.
80-
*
81-
* Default: true
67+
* When true, tasks are dispatched asynchronously to avoid blocking.
8268
*/
8369
'background' => (bool) env('FEED_SCHEDULE_RUN_BACKGROUND', true),
8470
],
@@ -88,12 +74,7 @@
8874
*/
8975
'console' => [
9076
/**
91-
* Enables a progress bar when generating feeds in the console.
92-
*
93-
* When set to true, the feed:generate command will display a
94-
* progress bar showing the execution progress.
95-
*
96-
* Default: false
77+
* Show a progress bar when generating feeds in the console.
9778
*/
9879
'progress_bar' => (bool) env('FEED_CONSOLE_PROGRESS_BAR_ENABLED', false),
9980
],
@@ -105,7 +86,7 @@
10586
*
10687
* You may add your own transformers by implementing
10788
* `DragonCode\LaravelFeed\Contracts\Transformer` and registering the class
108-
* here, or publish a stub via the package's make command if available.
89+
* here.
10990
*/
11091
'transformers' => [
11192
Transformers\BoolTransformer::class,
@@ -128,9 +109,8 @@
128109

129110
'jsonl' => [
130111
/**
131-
* JSON encoding flags used when exporting feeds to JSON.
132-
*
133-
* The JSON_PRETTY_PRINT option is not available for JSON Lines files and will be ignored.
112+
* JSON encoding flags used when exporting feeds to JSON Lines format.
113+
* Pretty print is ignored for JSON Lines.
134114
*/
135115
'options' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
136116
],

src/Transformers/DateTimeTransformer.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DateTimeInterface;
88
use DragonCode\LaravelFeed\Contracts\Transformer;
9+
use Illuminate\Support\Carbon;
910

1011
use function config;
1112

@@ -21,13 +22,23 @@ public function allow(mixed $value): bool
2122
*/
2223
public function transform(mixed $value): string
2324
{
24-
return $value->format(
25-
$this->format()
26-
);
25+
return $this->resolve($value)
26+
->when($this->timezone(), fn (Carbon $date, string $zone) => $date->setTimezone($zone))
27+
->format($this->format());
28+
}
29+
30+
protected function resolve(mixed $date): Carbon
31+
{
32+
return Carbon::parse($date);
2733
}
2834

2935
protected function format(): string
3036
{
31-
return config('feeds.formats.date');
37+
return config('feeds.date.format');
38+
}
39+
40+
protected function timezone(): string
41+
{
42+
return config('feeds.date.timezone');
3243
}
3344
}

0 commit comments

Comments
 (0)