ctrlo / GADS

Globally Accessible Data Store
GNU Affero General Public License v3.0
4 stars 8 forks source link

Updated audit to use local timezone #400

Closed droberts-ctrlo closed 3 months ago

droberts-ctrlo commented 5 months ago

Do I need to update the filters to use localtime as well?

abeverley commented 4 months ago

A bit of a rework on this needed I'm afraid... The time should always be stored in the database as UTC, so that it's an absolute value without needing to know the timezone. Then, when it's retrieved, it should be formatted accordingly.

There is already some of this in the code, such as https://github.com/ctrlo/GADS/blob/038b1024bc7e376d7fe0e115aeaf553f4a90155e/lib/GADS/Datum.pm#L283 whereby the timezone is converted to London timezone (automatically adjusting for daylight saving).

What would be better is if there was a central function to convert times accordingly. In the longer-term this could be defined per-user, but in the short-term a simple function such as the following could be added to the DateTime class by adding something like the following to GADS.pm:

Sub::Install::install_sub({
    code => sub {
        my $self = shift;
        # Do not alter original object
        my $clone = $self->clone;
        # Set to baseline timezone if timezone not-existing
        $clone->time_zone->is_floating && $clone->set_time_zone('UTC');
        $clone->set_time_zone('Europe/London'); # Can be customised later
        $clone->strftime('%e %b %Y %H:%M');
    },
    into => "DateTime",
    as   => 'gads_time', # Could be replicated as gads_date for just date
});

And then used such as print $datetime->gads_time

abeverley commented 3 months ago

I think just one final thing before I merge, I think we should include seconds in the time?