mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Playing around with local date time parsing.
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
namespace FireflyIII\Casts;
|
namespace FireflyIII\Casts;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Carbon\CarbonImmutable;
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
@@ -19,13 +18,11 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class SeparateTimezoneCaster implements CastsAttributes
|
class SeparateTimezoneCaster implements CastsAttributes
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Cast the given value.
|
|
||||||
*
|
|
||||||
* @param array<string, mixed> $attributes
|
* @param array<string, mixed> $attributes
|
||||||
*/
|
*/
|
||||||
public function get(Model $model, string $key, mixed $value, array $attributes): ?Carbon
|
public function get(Model $model, string $key, mixed $value, array $attributes): ?Carbon
|
||||||
{
|
{
|
||||||
if('' === $value || null === $value) {
|
if ('' === $value || null === $value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$timeZone = $attributes[sprintf('%s_tz', $key)] ?? config('app.timezone');
|
$timeZone = $attributes[sprintf('%s_tz', $key)] ?? config('app.timezone');
|
||||||
|
@@ -26,6 +26,16 @@ $.ajaxSetup({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function parseToLocalDates() {
|
||||||
|
"use strict";
|
||||||
|
$('span.date-time').each(function () {
|
||||||
|
var date = $(this).data('date');
|
||||||
|
var obj = moment.utc(date).local();
|
||||||
|
var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
$(this).text(obj.format(date_time_js) + ' ('+ timeZone +')');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@@ -96,6 +106,9 @@ $(function () {
|
|||||||
// trigger list thing
|
// trigger list thing
|
||||||
listLengthInitial();
|
listLengthInitial();
|
||||||
|
|
||||||
|
// update dates:
|
||||||
|
parseToLocalDates();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function currencySelect(e) {
|
function currencySelect(e) {
|
||||||
|
@@ -26,6 +26,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
// general stuff:
|
// general stuff:
|
||||||
|
'stored_as_tz' => 'stored as ":timezone"',
|
||||||
'close' => 'Close',
|
'close' => 'Close',
|
||||||
'actions' => 'Actions',
|
'actions' => 'Actions',
|
||||||
'edit' => 'Edit',
|
'edit' => 'Edit',
|
||||||
|
@@ -44,6 +44,7 @@ var todayText = ' {{ trans('firefly.today')|escape('js') }}';
|
|||||||
|
|
||||||
// some formatting stuff:
|
// some formatting stuff:
|
||||||
var month_and_day_js = "{{ trans('config.month_and_day_js') }}";
|
var month_and_day_js = "{{ trans('config.month_and_day_js') }}";
|
||||||
|
var date_time_js = "{{ trans('config.date_time_js') }}";
|
||||||
var acc_config_new = {format: accountingConfig};
|
var acc_config_new = {format: accountingConfig};
|
||||||
|
|
||||||
// strings and translations used often:
|
// strings and translations used often:
|
||||||
|
@@ -74,10 +74,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td style="width:30%;">{{ trans('list.date') }}</td>
|
<td style="width:30%;">{{ trans('list.date') }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
<span class="date-time" data-date="{{ first.date.toIso8601ZuluString() }}">
|
||||||
{{ first.date.isoFormat(dateTimeFormat) }}
|
{{ first.date.isoFormat(dateTimeFormat) }}
|
||||||
{% if(first.date_tz != '') %}
|
{% if(first.date_tz != '') %}
|
||||||
({{ first.date_tz }})
|
({{ trans('firefly.stored_as_tz', {timezone: first.date_tz }) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Reference in New Issue
Block a user