|
|
@@ -357,21 +357,32 @@ class MacroServiceProvider extends ServiceProvider
|
|
357
|
357
|
return $this;
|
|
358
|
358
|
});
|
|
359
|
359
|
|
|
|
360
|
+ // In your macro - simpler logic
|
|
360
|
361
|
TextColumn::macro('asRelativeDay', function (?string $timezone = null): static {
|
|
361
|
362
|
$this->formatStateUsing(function (TextColumn $column, mixed $state) use ($timezone) {
|
|
362
|
363
|
if (blank($state)) {
|
|
363
|
364
|
return null;
|
|
364
|
365
|
}
|
|
365
|
366
|
|
|
366
|
|
- $date = Carbon::parse($state)
|
|
367
|
|
- ->setTimezone($timezone ?? $column->getTimezone());
|
|
|
367
|
+ $timezone ??= $column->getTimezone() ?? CompanySettingsService::getDefaultTimezone();
|
|
|
368
|
+
|
|
|
369
|
+ // Use shiftTimezone to shift UTC calendar date to the specified timezone
|
|
|
370
|
+ // Using setTimezone would convert which is wrong for calendar dates
|
|
|
371
|
+ $date = Carbon::parse($state)->shiftTimezone($timezone);
|
|
368
|
372
|
|
|
369
|
373
|
if ($date->isToday()) {
|
|
370
|
374
|
return 'Today';
|
|
|
375
|
+ } elseif ($date->isTomorrow()) {
|
|
|
376
|
+ return 'Tomorrow';
|
|
|
377
|
+ } elseif ($date->isYesterday()) {
|
|
|
378
|
+ return 'Yesterday';
|
|
371
|
379
|
}
|
|
372
|
380
|
|
|
373
|
381
|
return $date->diffForHumans([
|
|
374
|
382
|
'options' => CarbonInterface::ONE_DAY_WORDS,
|
|
|
383
|
+ 'skip' => ['month', 'week'], // Skip larger units, force days and years only
|
|
|
384
|
+ 'parts' => 2,
|
|
|
385
|
+ 'join' => ', ',
|
|
375
|
386
|
]);
|
|
376
|
387
|
});
|
|
377
|
388
|
|
|
|
@@ -384,15 +395,25 @@ class MacroServiceProvider extends ServiceProvider
|
|
384
|
395
|
return null;
|
|
385
|
396
|
}
|
|
386
|
397
|
|
|
387
|
|
- $date = Carbon::parse($state)
|
|
388
|
|
- ->setTimezone($timezone ?? $entry->getTimezone());
|
|
|
398
|
+ $timezone ??= $entry->getTimezone() ?? CompanySettingsService::getDefaultTimezone();
|
|
|
399
|
+
|
|
|
400
|
+ // Use shiftTimezone to shift UTC calendar date to the specified timezone
|
|
|
401
|
+ // Using setTimezone would convert which is wrong for calendar dates
|
|
|
402
|
+ $date = Carbon::parse($state)->shiftTimezone($timezone);
|
|
389
|
403
|
|
|
390
|
404
|
if ($date->isToday()) {
|
|
391
|
405
|
return 'Today';
|
|
|
406
|
+ } elseif ($date->isTomorrow()) {
|
|
|
407
|
+ return 'Tomorrow';
|
|
|
408
|
+ } elseif ($date->isYesterday()) {
|
|
|
409
|
+ return 'Yesterday';
|
|
392
|
410
|
}
|
|
393
|
411
|
|
|
394
|
412
|
return $date->diffForHumans([
|
|
395
|
413
|
'options' => CarbonInterface::ONE_DAY_WORDS,
|
|
|
414
|
+ 'skip' => ['month', 'week'], // Skip larger units, force days and years only
|
|
|
415
|
+ 'parts' => 2,
|
|
|
416
|
+ 'join' => ', ',
|
|
396
|
417
|
]);
|
|
397
|
418
|
});
|
|
398
|
419
|
|
|
|
@@ -473,9 +494,8 @@ class MacroServiceProvider extends ServiceProvider
|
|
473
|
494
|
Carbon::macro('toDefaultDateFormat', function () {
|
|
474
|
495
|
$companyId = auth()->user()?->current_company_id;
|
|
475
|
496
|
$dateFormat = CompanySettingsService::getDefaultDateFormat($companyId);
|
|
476
|
|
- $timezone = CompanySettingsService::getDefaultTimezone($companyId);
|
|
477
|
497
|
|
|
478
|
|
- return $this->setTimezone($timezone)->format($dateFormat);
|
|
|
498
|
+ return $this->format($dateFormat);
|
|
479
|
499
|
});
|
|
480
|
500
|
|
|
481
|
501
|
ExportColumn::macro('money', function () {
|