Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #30, on April 6th, 2012, 05:07 PM »
Quote
Isn't this a complete list of all timezones?
Also, is the fact that I was by default on UTC/Dublin due to me probably not going to that area before, and thus having no default timezone...? Because I saved my time format, and didn't notice the timezone at that moment, and I immediately got an incorrect forum time (well, YOUR correct forum time if you prefer :P). I had to go back to the page and noticed that it was Dublin by default.
No, it's not a complete list of all timezones. There are nearly 500 (no that's not a typo) timezones to contend with. I've reduced it to a list of about 70 (75 IIRC) which are comparable to the ones Windows uses. Incidentally I think you'll find XenForo uses a similar if not the same list.

The timezone code has a bug where it can display the wrong entry in the list if the underlying timezone identifier has a _ in it. This is not a new bug and was discussed and investigated last week, I just haven't fixed it yet. But it still saves the correct timezone.

Check the timezone column in wedge_members to see what it's actually using for you - I'm on UTC Dublin, despite the server not being so.

Also, as far as I can determine, Amsterdam is not the same physical timezone but shares all the same rules with the Central European timezones, so that it is to all intents and purposes the same.


Regarding dates, I don't have a better solution, I'd prefer it to be as 'right' as possible, ultimately. April 1st would be better than April 1 which would be better than 1 April, but it's almost more a preference than anything else right now.

And yeah, optimising timeformat is one of those cases that it'd be neat but ultimately not a huge win in the scheme of things (IIRC, I already did some work to make it faster than SMF's by changing the setlocale call handling)
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: timeformat annoys me...
« Reply #31, on April 12th, 2012, 02:51 PM »
Quote from Arantor on April 6th, 2012, 05:07 PM
No, it's not a complete list of all timezones. There are nearly 500 (no that's not a typo) timezones to contend with. I've reduced it to a list of about 70 (75 IIRC) which are comparable to the ones Windows uses. Incidentally I think you'll find XenForo uses a similar if not the same list.
Hmm it's complicated...
Quote
Check the timezone column in wedge_members to see what it's actually using for you - I'm on UTC Dublin, despite the server not being so.
I was in UTC Dublin by default (i.e. not having set a timezone...), which is logical since if no timezone is set, Wedge will put "selected" on that entry.
So I changed my time format but forgot to also set my timezone, and as a result my forum pages were all showing dates that were late by one hour. :(
Meaning that Wedge should try and determine which timezone to use by default.
Quote
Also, as far as I can determine, Amsterdam is not the same physical timezone but shares all the same rules with the Central European timezones, so that it is to all intents and purposes the same.
UTC+1 - Amsterdam, Rome, Berlin, Vienna...
UTC+1 - Brussels, Copenhagen, Madrid, Paris...

If Copenhagen, which is further east compared to Amsterdam, is in the same timezone as Madrid which is further west to it, it probably means that they don't share the same 'rules' when it comes to daylight savings etc... Maybe they're set on a different (but close enough) day, I don't know.
What I know though, is that Wedge is 50% French and I demand a Paris timezone in the list :lol:
Quote
Regarding dates, I don't have a better solution, I'd prefer it to be as 'right' as possible, ultimately. April 1st would be better than April 1 which would be better than 1 April, but it's almost more a preference than anything else right now.
After a few days of use, I decided that I'd rather have a (very slightly) slower Wedge that does dates correctly, unlike other forum systems. :)

I was thinking of something, can you tell me what you think...?
So, we have a UNIX timestamp to begin with. Doing $timestamp - ($timestamp % 1800) will round it to the half-hour, and since no timezones exist that require a 15mn granularity, it means that all dates between 14:00 and 14:30 (for instance) will be on the same day (whatever the server time), and will thus use the same code path.

So, I'm suggesting this: store the rounded time in a static array, and if it's set, get the format from it. Otherwise, just calculate the format and then store it in the index as the rounded time.
Although it won't be helpful everywhere, just imagine a topic page... If some people start discussing like they're on a chat, you can end up caching the time format for nearly every single date retrieved from that page.

What do you think...? Does it work as a concept?
Quote
And yeah, optimising timeformat is one of those cases that it'd be neat but ultimately not a huge win in the scheme of things (IIRC, I already did some work to make it faster than SMF's by changing the setlocale call handling)
Yeah, I remember that, it was a good idea :)

PantsManUK

  • [me=PantsManUK]would dearly love to dump SMF 1.X at this juncture...[/me]
  • Posts: 174
Re: timeformat annoys me...
« Reply #32, on April 12th, 2012, 03:03 PM »
Getting back to the most immediate topic at hand (suffixes for dates), ignore the English suffixes when a non-English language is in use. Over-write the strings if that would help...
« What is this thing you hoomans call "Facebook"? »

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: timeformat annoys me...
« Reply #33, on April 12th, 2012, 03:11 PM »
Quote from PantsManUK on April 12th, 2012, 03:03 PM
Getting back to the most immediate topic at hand (suffixes for dates), ignore the English suffixes when a non-English language is in use. Over-write the strings if that would help...
No, can't do something specific like that... It would need to be built into the language loader (i.e. load English, and if another language is loaded, unset all English suffixes first), and I don't really like the idea.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #34, on April 12th, 2012, 03:15 PM »
Quote
since no timezones exist that require a 15mn granularity,
Yes there are, actually. India, for one.

But it's still kind of moot. There absolutely MUST be a timezone set. You can't even call time(), without having a timezone being set because PHP will complain bitterly. Same with strftime, date etc. And given that we already have to do that, it's no biggie to get the user's timezone that they've set, which allows us to calculate the offset relative to server time, including DST, and get it right. IIRC I implemented it so it calculated the time_format and overrode what the user had otherwise set to preserve codepaths.
Quote
So I changed my time format but forgot to also set my timezone, and as a result my forum pages were all showing dates that were late by one hour.
The time format should now be obsolete, and only timezone should be set. There's no clean way to determine a user's timezone by anything supplied by the user, far better that instead ask the user what their timezone is on registration. (This is not yet implemented but I'll add that in due course)
Quote
No, can't do something specific like that... It would need to be built into the language loader (i.e. load English, and if another language is loaded, unset all English suffixes), and I don't really like the idea.
It does have to be in the language loader, but you have choices in how it's done.

What you can do, if you want, is implement it as an array, such as:
Code: [Select]
$txt['day_suffix'] = array(
  1 => 'st',
  2 => 'nd',
  3 => 'rd',
  'n' => 'th',
);

Or, as previously discussed creating a set of prefixes. But this seems cleaner to me - and you can have it expanded automatically into a normal set of day_suffix_1, day_suffix_2 etc in loadLanguage, when the loaded language file is 'index', and have it automatically unset all of them and build them out of just this array.

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: timeformat annoys me...
« Reply #35, on April 12th, 2012, 03:48 PM »
- There's only one timezone that isn't based on increments of 30mn, and it's Katmandu, Nepal. I don't think that Nepal is worth bothering too much about proper time offsets.
So, I've done some testing with this mini-cache... Turns out that it can save up to 50% performance when applied to topics with chat-like conversations. However, in other situations it doesn't save anything (oddly, I could even reproduce a case where it made everything slightly slower...)
Still, given that we're mostly within a one-millisecond performance optimization, maybe it just isn't worth getting into a fight with Nepal. :P

- time format isn't obsolete. I think you confused it with time offset...?

- using an array is a good suggestion indeed. Here's wondering, though, if it'd be worth it in terms of PHP parsing... I know that for instance, if you add an unserialize() call within a language file, or any file, it actually loads much faster than the regular array notation. Also... Where should we build support for arrays? In number_context() directly? Or in the first call to timeformat()?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #36, on April 12th, 2012, 03:57 PM »
Hmm, I thought India was +5:45, but it seems to be +5:30.

And yes, I did get it confused with time_offset. (Am not at home today but have laptop with me)

Thing is, if we're being correct about suffixes, I'd prefer to be correct across the board ;)

As far as using that array goes, do it in loadLanguage, if the loaded language file is 'index'. It's called only a few times per page, far fewer than timeformat or number_context is.

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: timeformat annoys me...
« Reply #38, on April 12th, 2012, 05:23 PM »
Having issues with loadLanguage.

Basically, I want to call that code only once... But how do I determine that I'm in a 'first loop' and should skip? I could test for $fatal, because it's only set for Settings and ThemeStrings (which IIRC are deprecated...? At least ThemeStrings?!), but it feels like a bit of a hack... if (!$fatal && $template_name === 'index')... Would that be okay?

:edit: if ($fatal), sorry.
Posted: April 12th, 2012, 05:11 PM

Okay, I added a new param, $fallback, which should make it less of a hack now... ;)
It seems to be working, too. I added the code in the code block that was already dealing with setlocale, meaning it saves time because in fallback mode it would execute it twice.

And I think that it's safe enough to assume that all language files will have both $txt['time_format'] and $txt['day_suffix'] set (even to the same value as English is okay...)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #39, on April 12th, 2012, 06:31 PM »
But surely you can't do it only once? If you load French, you load French after you load English... so you need to rebuild it when French is loaded - surely you need to do it just when $template_name === 'index' so that you always rebuild it properly when changing languages?

(That does raise questions for switching languages e.g. for emails but IIRC index isn't used then anyway)

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: timeformat annoys me...
« Reply #40, on April 12th, 2012, 07:02 PM »
Quote from Arantor on April 12th, 2012, 06:31 PM
But surely you can't do it only once?
Don't call me Shirley!™
Quote
If you load French, you load French after you load English... so you need to rebuild it when French is loaded - surely you need to do it just when $template_name === 'index' so that you always rebuild it properly when changing languages?
I don't see the point in doing it twice with fallback. You only need to do it for the target language... Hence the $fallback bool I added. setlocale and day_suffix are now both skipped when the loop is in fallback mode.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,078