Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save local timezone #911

Closed
ge0ffray opened this issue Sep 25, 2021 · 8 comments
Closed

Save local timezone #911

ge0ffray opened this issue Sep 25, 2021 · 8 comments
Milestone

Comments

@ge0ffray
Copy link

Hello,

As correctly explained here, when saving to GPX, KML, or custom URL, points are logged using UTC time.

If we want to use the log file in any application, it means we must remember ourself where the log was recorded (I mean in which timezone). If I recorded an activity at the other end of the world, I'll probably want to display that activity using the timezone of the country I was, not the timezone of the country I'm currently in.

These files saved by GPSLogger currently do not give any way to know the local timezone. If I forget in which country the log was recorded, there's no way convert logs to local dates; except using a third-party webservice (like theses), which are often not free to use.

I think it would be nice to add an extra information to allow these date conversions

Thanks

@dshanske
Copy link

I'd like this as an option in the custom URL

@mendhak
Copy link
Owner

mendhak commented Sep 26, 2021

I'm trying to think of the least friction way of doing this. I'm aware GPX extensions exist, but there's no guarantee that all applications read what I come up with, or if there are any well known GPX extensions for storing an additional piece of info like this. I wasn't able to find anything well known to store offsets.

Would it be useful instead if I introduced some toggle like "Record local timezone anyway". If you toggle it, then the <time> will be written with the offset, instead of the UTC Z. In other words, I drop this strictness highlighted in the FAQ item. The user can knowingly choose to have the timezone offset in the GPX file even if it's 'incorrect'. I say 'incorrect' because after some searching I'm not sure if this is enforced or not.

Some validation will be required right now, what you could do is test your existing GPX files, edit them to have an offset, and see if your applications accept it.

Like:

2021-09-26T11:55:36.7+01:00
2021-09-26T11:55:36.700+01:00

At a glance there seem to be some classes in Java that can help me here, but it will require Android 24+ or Android 26+ (Android 7+ or 8+). For my own reference the ZonedDateTime could help me greatly. I can take the location epoch passed from the OS, and convert it to the user's time. Then easily write it out to the formats shown above.

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(loc.getTime()), TimeZone.getDefault().toZoneId());
    String withOffset1 = zoned.toOffsetDateTime().toString();
    String withOffset2 = zoned.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}

@MexasPT
Copy link

MexasPT commented Sep 28, 2021

I've had the same problem for a month...
I'm importing csv into a mysql table, but I wanted to add 1 hour...
Someone explain to me how to add a time in > $data[0] ?!

$data[0] is the coll 2021-09-27T10:46:09

Thanks!!!

CODE:
`$speedcorr = 3.6 * $data[6];

$query = 'INSERT INTO positions (time, v_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, created_date) 

VALUES ("'.$data[0] . '", "1", "' . $data[1].'", "' . $data[2] . '", "' . $data[3] . '", "' . $speedcorr . '", "' . $data[5] . '", "' . $data[4] . '", "' . $data[8] . '", "' . $data[16] . '", "' . $data[0] . '")';

@mendhak
Copy link
Owner

mendhak commented Sep 29, 2021

@MexasPT I think that's PHP?

I am not PHP savvy but something like this should work. DateTime should be able to read ISO8601 strings.

$dt = new DateTime($data[0]);
$dt->modify('+ 1 hour');
$result = $dt->format(DateTime::ATOM);

$query = 'INSERT INTO positions (time, v_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, created_date) 
VALUES ("'.$result. '", "1", "' . $data[1].'", "' . $data[2] . '", "' . $data[3] . '", "' . $speedcorr . '", "' . $data[5] . '", "' . $data[4] . '", "' . $data[8] . '", "' . $data[16] . '", "' . $data[0] . '")';

@mendhak
Copy link
Owner

mendhak commented Oct 1, 2021

I might be able to use this, should work on older Android versions too. The Calendar is used just to figure out the timezone.

    public static String getIsoDateTimeWithOffset(Date dateToFormat){
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        SimpleDateFormat ISO_8601_DATE_TIME = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ", Locale.US);
        ISO_8601_DATE_TIME.setTimeZone(calendar.getTimeZone());
        String dateTimeStringWithOffset = ISO_8601_DATE_TIME.format(dateToFormat);
        //Fix for older Android where ZZZZZ does not include colon
        if (!dateTimeStringWithOffset.substring(dateTimeStringWithOffset.length() - 3).startsWith(":")) {
            dateTimeStringWithOffset = dateTimeStringWithOffset.substring(0, dateTimeStringWithOffset.length() - 2) + ":" + dateTimeStringWithOffset.substring(dateTimeStringWithOffset.length() - 2);
        }
        return dateTimeStringWithOffset;
    }

mendhak added a commit that referenced this issue Oct 3, 2021
…rmat with timezone offset. eg 2016-03-05T21:24:29.949+02:00

Issue #911
@mendhak
Copy link
Owner

mendhak commented Oct 4, 2021

Today I played a bit with a GPX file, I deliberately modified all the timestamps to have a timezone offset in it. I then tested it with exiftool, GPXSee, GPSVisualizer, UTrack.

They were all able to read the times with the offsets. So I'm thinking to add a setting to just go ahead and give the option. In the 'logging preferences' screen, how's something like this (default false)

image

mendhak added a commit that referenced this issue Oct 5, 2021
@mendhak
Copy link
Owner

mendhak commented Oct 8, 2021

New option added under Logging details, under advanced settings. You can write times with timezone offset where possible (GPX, KML, GeoJSON). It will write the datetime in ISO8601 format with timezone offset. eg 2016-03-05T21:24:29.949+02:00

Custom URL gets a %TIMEOFFSET parameter.
CSV gets a new field time_offset.

I've put a test APK here: https://github.com/mendhak/gpslogger/releases/tag/v119-rc1
As usual, this APK is not compatible with the F-Droid version.
If you install this APK you will lose all GPSLogger data from the F-Droid version.

@mendhak mendhak added this to the v119 milestone Oct 30, 2021
@mendhak
Copy link
Owner

mendhak commented Nov 11, 2021

v119 is now on F-Droid and in the releases. I'm going around and closing some issues.

@mendhak mendhak closed this as completed Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants