Nao

  • Dadman with a boy
  • Posts: 16,082
Re: timeformat annoys me...
« Reply #15, on April 5th, 2012, 02:57 PM »
I'm calling trim() (or more specifically, ltrim because these never generate right padding AFAIK), on the final strftime() call, you know, just inside the return call...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #16, on April 5th, 2012, 03:02 PM »
I'm now thoroughly confused. You wanted to deal with the left spacing on the number, and suggested using trim(), I just suggested a variation on that which didn't use %e, nothing more.

For cases where there's an extra space in the middle of the string, you're still stuffed either way, whether you use ltrim() or trim(), aren't you?
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,082
Re: timeformat annoys me...
« Reply #17, on April 5th, 2012, 03:37 PM »
Quote from Arantor on April 5th, 2012, 03:02 PM
I'm now thoroughly confused. You wanted to deal with the left spacing on the number, and suggested using trim(), I just suggested a variation on that which didn't use %e, nothing more.
Okay, hmmm... Okay can I say that?

Let's say we have this:

Most users online: 127 (December  2)

In French, that would be:

Records de visiteurs : 127 ( 2 Décembre)

Notice the position of the extra space. Because HTML is pretty cool when it comes to multiple spaces, it will only show one space in "December 2", but will show the extra space in French.

My goal was initially to fix %e to return no padding. However, I don't really care that %e returns an extra space when HTML will deal with it. It's not a big deal... So, in the meantime I figured I should just call ltrim() on the final string (" 2 Décembre"). Do you understand what I mean...?
Quote
For cases where there's an extra space in the middle of the string, you're still stuffed either way, whether you use ltrim() or trim(), aren't you?
Yeah, but does it matter? Do you know of any language where the standard for dates is something like "Djèkêmbërr (2)"? In that case, yeah, that string would get the extra space... But I'm trying to work out of a 'realistic' goal, i.e. the most likely languages to be seen. English has an 80% chance to be used, Turkish has a pretty high chance too (in SMF at least -- in Wedge it's gonna start slow), and French will certainly be in the Top 5. So it needs some love.

And you're lucky, I haven't come around to adding the "1er" thingy. :P (Although we could somehow do it by, for instance, adding a custom %variable, which could be transformed at runtime to $txt['strftime_finish_n'] = 'th'; $txt['strftime_finish_1'] = 'st'; $txt['strftime_finish_2'] = 'nd'; $txt['strftime_finish_3'] = 'rd'; -- hmm... I'm a bit crazy :P Perhaps there's already such a thing built into PHP...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #18, on April 5th, 2012, 03:41 PM »
Quote
My goal was initially to fix %e to return no padding. However, I don't really care that %e returns an extra space when HTML will deal with it. It's not a big deal... So, in the meantime I figured I should just call ltrim() on the final string (" 2 Décembre"). Do you understand what I mean...?
I do, but somehow I had it in my brain that it was more complicated.

In any case, typically in America they write the date as Month Day, Year, so you get two spaces into the mix.

There is no magic st/nd/rd in PHP AFAIK.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: timeformat annoys me...
« Reply #19, on April 5th, 2012, 03:59 PM »
Two spaces? Not one?

About 1st etc, I guess this could be done... Really, adding a %wd (Wedge day) or something, which we strpos in timeformat(), and str_replace with ($day = ltrim(strftime('%d', $date))) . (isset($txt['date_day_finish_' . $date]) ? $txt['date_day_finish_' . $date] : $txt['date_day_finish_n'])... Would that do? Something like that (not tested :P)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #20, on April 5th, 2012, 04:12 PM »
Sure it would be two spaces, because if you have say March 5, you'd get March(normal space that would be there anyway)(space that would be left from %e)5.

Yes, what you're proposing should do the trick, though I'm not sure about speed necessarily :/

PantsManUK

  • [me=PantsManUK]would dearly love to dump SMF 1.X at this juncture...[/me]
  • Posts: 174
Re: timeformat annoys me...
« Reply #21, on April 5th, 2012, 04:13 PM »
Quote from Arantor on April 5th, 2012, 03:41 PM
There is no magic st/nd/rd in PHP AFAIK.
Eh? God is dead... :sob:

PHP does do English ordinal suffixes for the day of the month.

Code: [Select]
<?php
// Prints something like: Monday 8th of August 2005 03:12:46 PM
date('l jS \of F Y h:i:s A');
?>

:edit: Ah, not in strftime() it doesn't. To quote from the comments however:-

Code: [Select]
dgudgeon at example dot com 14-Jul-2011 05:04
If moving from date() to strftime() to support additional languages, you may miss the ordinal suffix format option date('S'). Workaround this by adding an extra modifier (%O).

<?php
function my_strftime ($format$timestamp)
{
    
$format str_replace('%O'date('S'$timestamp), $format);    
    return 
strftime($format$timestamp);
}
?>
« What is this thing you hoomans call "Facebook"? »

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: timeformat annoys me...
« Reply #22, on April 5th, 2012, 04:18 PM »
Yeah but it's date(), so it would require doing some conversion work anyway... (from % variables to single-letter variables, at the very least.)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #23, on April 5th, 2012, 05:06 PM »
And that's the thing, date() doesn't take locale settings into account, meaning it will only support English, it won't support any other language - something that strftime does do... as you mentioned.

I see what you mean about the helper function but that's really not helpful in performance terms - timeformat is called at least once every page, and for many pages it's called 20+ times, and adding that helper function is going to make it slower.

PantsManUK

  • [me=PantsManUK]would dearly love to dump SMF 1.X at this juncture...[/me]
  • Posts: 174
Re: timeformat annoys me...
« Reply #24, on April 5th, 2012, 05:15 PM »
I see. Rock and a hard place. :hmm:

You *could* do a single-pass function that regexes for dates in the output and inserts the locale-correct suffixes as necessary, but that's a heck of a lot of work for tiny bit of gain (the page will grammer correctly). Me, I say f*** it and leave the "naked number"; folks will learn to love it...

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: timeformat annoys me...
« Reply #25, on April 6th, 2012, 04:14 PM »
So, I implemented the stuff and it works.

I named it %@ so that it doesn't clash with other names.
It should be noted, however, that I met a bug in Wedge's number_context() that I won't be able to fix without rethinking the whole thing.

Indeed, let's say I define custom lines for _n, _1, _2 and _3 in English (which is the case here obviously.) And custom lines for _n and _1 in French (it only needs 'premier/1er').
Now, what happens if you're in French mode and asking to convert an April 2 date?
Well I'll tell you. It won't find a custom _2 in the French language, but because it loads the English file as well, it does find it in English, and thus I find myself with a beautiful "2nd avril" as the date... Argh.

Any ideas, Pete? Having to add dummy entries for other languages (i.e. just reproduce what _n does in _2, _3, _21, _22, _23 and _31) is a sad waste of time and space... It does seems like the only 'logical' solution, but it certainly hurts extensibility a bit.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #26, on April 6th, 2012, 04:28 PM »
Is there not an actual linguistic equivalent in French for 2nd? I always thought there was.

And sadly there isn't a good way around this one - normally it's not a huge problem because most of the time we only have _1 and _n strings in English which will naturally be overridden in other languages. I don't think you can get around it, unless you drop it in English entirely and just leave it in other languages if they want to do so.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: timeformat annoys me...
« Reply #27, on April 6th, 2012, 04:35 PM »
Quote from Arantor on April 6th, 2012, 04:28 PM
Is there not an actual linguistic equivalent in French for 2nd? I always thought there was.
A small French lesson if you're interested :)
We have this list:
Premier, second (but we can also say "deuxième", they're both correct), troisième, quatrième, cinquième, sixième...
1er, 2nd (2ème), 3ème, 4ème, 5ème....
Basically, our "ème" is your "th", and we have "er" and "nd", BUT, this is only for enumerating things... When it comes to dates, we don't say "Avril le second", we say "Le deux avril", whether written or orally. So that is, "2 avril". But April 1st is "Le premier avril", so "1er avril". Seeing "1 avril" is grammatically incorrect in French (we can't say "Le un avril"), which is why I could never stand how French dates are implemented in computer systems in general... And everytime we roll back to the 1st of a month, I immediately cringe at the "1 (month name)" in the topic list...
Quote
And sadly there isn't a good way around this one - normally it's not a huge problem because most of the time we only have _1 and _n strings in English which will naturally be overridden in other languages. I don't think you can get around it, unless you drop it in English entirely and just leave it in other languages if they want to do so.
Hmm... But English has its rules, too. Grammatically, I'm pretty sure that "April the 1" is as bad as in French... :P

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: timeformat annoys me...
« Reply #28, on April 6th, 2012, 04:45 PM »
Yay, dates are just as much of a shit to cope with as timezones are!

Anyway, yes, English has rules, and they're all insane and largely ignored.

Consider this: April 1 - that's mostly how the Americans write it, and it's wrong, because it should really be April 1st, never mind the implied but missing 'the' in the middle that you mention.

But the English get it wrong too. We tend to write 1 April or 1st April, but that's linguistically wrong too - it's really '1st (of) April' with the implication of 'day' being in there.

Fortunately most people aren't anal enough to care about this and don't really notice it when it's 1 April or April 1 with or without the suffix, it's only those of us who *really* put in the attention to detail that would even notice, let alone do anything about it.

(For the record, it's something I'd like to see done right too, but I didn't know enough about how other languages did it to make a judgement call on how it should be done)

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: timeformat annoys me...
« Reply #29, on April 6th, 2012, 04:56 PM »
Quote from Arantor on April 6th, 2012, 04:45 PM
Yay, dates are just as much of a shit to cope with as timezones are!
Oh, and I didn't even tell you yet...
When I when to change my time format, I noticed that my timezone was set to UTC/Dublin. No Paris in there. Looked into the list... No Paris either. Uh. After checking with Windows -- the Amsterdam (CET+1) timezone is different from the Brussels/Paris timezone (although also at CET+1). And it doesn't seem to be handled by Wedge at all...?
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.

I can already see the amount of support messages about this one...
Quote
Consider this: April 1 - that's mostly how the Americans write it, and it's wrong, because it should really be April 1st, never mind the implied but missing 'the' in the middle that you mention.
And it's good this way :P April 1st is what comes to mind naturally to me...
Quote
But the English get it wrong too. We tend to write 1 April or 1st April, but that's linguistically wrong too - it's really '1st (of) April' with the implication of 'day' being in there.
"1 April" sounds awfully wrong to me...
Quote
Fortunately most people aren't anal enough to care about this and don't really notice it when it's 1 April or April 1 with or without the suffix, it's only those of us who *really* put in the attention to detail that would even notice, let alone do anything about it.
So... Do you have any suggestions on the current affair at hand?
Quote
(For the record, it's something I'd like to see done right too, but I didn't know enough about how other languages did it to make a judgement call on how it should be done)
I think there's no 'right' way to do it -- they're all going to slow down the system.
But it can be optimized I suppose...
For instance, we could benchmark multiple strftime calls against something like explode(' ', strftime('%m %d %y %h %i %s')) (and the equivalent date()), with subsequent use of $txt['days'], $txt['months'] or things like that...
Thing is, I have no idea whether strftime is THAT slow. It seemed pretty pointless to try and optimize it further after I noticed that it took over 30.000 calls to timeformat() to get it to take a second to execute...!