pebble-hacks / aviator

Aviator Watchface
24 stars 3 forks source link

Zulu/Local Time #1

Closed orviwan closed 10 years ago

orviwan commented 10 years ago

In the configuration screen, set Style=Local/Zulu.

This displays 2 clocks, the top one should display local time, the bottom one should display Zulu (UTC).

Both clocks currently display the same time, even though we correctly calculate the offset.

Jnmattern commented 10 years ago

Hi Orviwan, for this one I can help : localtime returns a struct tm * pointer that's always pointing to the same address, it's not a dynamically allocated struct. This means the value is overwritten after each call to localtime.

The only way to achieve this is to declare a static struct tm and immediately after calling the localtime() function copy the return of localtime() into it, then use this static struct tm to call the updatezulu* function passing a ref to it.

For example: time_t utc = time(NULL) + mTimezoneOffset; struct tm zulu_time = *localtime(&utc); update_zulu_hours(&zulu_time);

Another problem you will probably have also is that your mTimezoneOffset variable is dynamically retrieved from the Phone using JSKit, this means it won't be set to the right value at launch if zulu time display is set. You should trigger a call to updatezulu*() in sync_tuple_changed_callback() when mTimezoneOffset value changes.

For example: case TIMEZONE_OFFSET_KEY: mTimezoneOffset = new_tuple->value->int32;

if (mStyle == 2) {
    time_t utc = time(NULL) + mTimezoneOffset;
    struct tm zulu = *localtime(&utc);
    update_zulu_hours(&zulu);
    update_zulu_minutes(&zulu);
    update_zulu_seconds(&zulu);
}

Sorry for describing all this instead of updating the source code, but I'm not used to github at all and don't know how I can propose changes (looks like it's called pull requests).

Hope this helps!

orviwan commented 10 years ago

This is great, I knew it would be something pointer related, but I have no idea about C :)

Thanks, I'll give it a go tonight.

Jon

On 20 Jan 2014, at 17:57, Jnmattern notifications@github.com wrote:

Hi Orviwan, for this one I can help : localtime returns a struct tm * pointer that's always pointing to the same address, it's not a dynamically allocated struct. This means the value is overwritten after each call to localtime.

The only way to achieve this is to declare a static struct tm and immediately after copy the return of localtime() into it, then use this static struct tm to call the updatezulu* function passing a ref to it.

For example: time_t utc = time(NULL) + mTimezoneOffset; struct tm zulu_time = *localtime(&utc); update_zulu_hours(&zulu_time);

Another problem you will probably have also is that your mTimezoneOffset variable is dynamically retrieved from the Phone using JSKit, this means it won't be set to the right value at launch if zulu time display is set. You should trigger in sync_tuple_changed_callback() calls to updatezulu*() when mTimezoneOffset value changes.

For example: case TIMEZONE_OFFSET_KEY: mTimezoneOffset = new_tuple->value->int32;

if (mStyle == 2) { time_t utc = time(NULL) + mTimezoneOffset; struct tm zulu = *localtime(&utc); update_zulu_hours(&zulu); update_zulu_minutes(&zulu); update_zulu_seconds(&zulu); }

Sorry for describing all this instead of updating the source code, but I'm not used to github at all and don't know how I can propose changes (looks like it's called pull requests).

Hope this helps!

— Reply to this email directly or view it on GitHubhttps://github.com/pebble-hacks/aviator/issues/1#issuecomment-32782111 .

orviwan commented 10 years ago

I've implemented this. It appears to be working, but can you take a look at this commented area //// BEGIN SECTION.

For some reason, without that code, the local/zulu time are the same. I don't understand why!