News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Integration hook for timeformat()

Started by asmith, January 21, 2016, 10:49:15 AM

Previous topic - Next topic

asmith

Hello,

Depending on the user language, I'm changing the timeformat. Because some of the languages/regions uses a different calendar. (I've written a small mod for my own use modifying timeformat())

This function gets called more often but is it a bad idea to put an integration hook into this function?

asmith

It's been 2 weeks since I posted this, so I hope bumping is not frowned upon :)

BUMP!

Integration hook for timeformat()? or some alternative way to change forum date without direct modifying SMF code?

margarett

There is no harm in calling a hook more than once. Yet, if what your hook loads doesn't change during the several calls you might consider to use static variables so that you only load their content once.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

asmith

Thanks for the reply.

I know I can simply modify my own code. I meant to consider adding an integration hook inside timeformat() for SMF 2.1 so that the timeformat() of the forum can be changed without having to touch SMF code. There are other dates than Gregorian calendar. (like Persian or Chinese ones) So having an integration hook inside that function, allows mods to change that without having to touch SMF's original code.

Kindred

it is unlikely that we will be adding additional hooks to the code at this point in time - given that we are working on releasing beta3 and have essentially called for a feature freeze.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

asmith

Fair enough. But would you consider it for the release after beta3?

margarett

Adding a hook is simple enough (so I'm sure it can be "fitted"), the only question is really the amount of calls in a single page load and I'm not sure about that.
Let's wait for a developer's input, so I tracked the question:
https://github.com/SimpleMachines/SMF2.1/issues/3279
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Sesquipedalian

Rather than hooking into timeformat(), wouldn't it work better to make sure that setlocale(LC_TIME'whatever') was set when the user changed their language? Setting LC_TIME correctly should make timeformat() return the calendar dates you are looking for every time.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Illori

not always does a user select a language based on location. what if you are studing a language but live in another country? you switch your language but dont want the timezone etc changed.

Sesquipedalian

True, but setting LC_TIME doesn't affect timezones. It changes how a date and time is formatted.


sh-3.2# LC_TIME='en_US.UTF-8' date "+%A %d %B %Y"
Wednesday 02 March 2016
sh-3.2# LC_TIME='he_IL.UTF-8' date "+%A %d %B %Y"
רביעי 02 מרץ 2016


Unfortunately, I was mistaken in my previous post in thinking that setting the LC_TIME variable would also change the calendar that was used, which is what asmith wants to do. As you can see, setting LC_TIME to he_IL.UTF-8 still spits out the year, month, and day number of the Gregorian calendar, just using the Hebrew translations as defined for that locale. So, not a solution for asmith's problem.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

asmith

As Illori mentioned, a user may want to keep using Gregorian calendar while changing language. A hook simply makes it possible for a mod to solve the problem. (that's a quick fix)

The ultimate solution would be letting the user select his/her own calendar, the same way he/she can select the language.

Advertisement: