Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

setting date&timezone


surcie

Recommended Posts

Posted

Hello,

 

In Footer, the constant FOOTER_TEXT_BODY, is called, and it's declared in catalog/includes/languages/yourlanguage.php

 

looking like:

 

define('FOOTER_TEXT_BODY', 'Copyright © ' . date('Y') . ' <a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . STORE_NAME . '</a><br>Powered by oscommerce');

 

On the other hand i had multiple E_STRICT errors with KissError handler regarding timezones, these errors disappeared when i replaced:

 

define('FOOTER_TEXT_BODY', 'Copyright ©' . date_default_timezone_set('Yourcountry') . ' <a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . STORE_NAME . '</a><br>Powered by oscommerce');

 

The problem is, this is probably not the best place to declare the timezone, and it prints a '1' before STORE_NAME.

 

I would like to know if it is ok to do this to declare the time_zone for a given language:

 

In catalog/includes/languages/yourlanguage.php

 

After

@setlocale(LC_TIME, 'pt_BR.ISO_8859-1');

 

Add:

date_default_timezone_set('Yourcountry');

 

Will this work for sitewide? of course you can select different timezones for each language, and will this work ok in terms of database saving the data correctly?

 

Thanks in advance.

Posted

You definitely don't want date_default_timezone_set() in the line that formats the date! You obviously don't understand what that call is for. It just sets a global setting for time and date calls, and belongs somewhere in the application_top.php files. If you want to give a different timezone setting for each language, you'd have to add some code after where the site language is determined (such as from the browser language setting) and map that to a proper timezone string before calling date_default_timezone_set(timezone name). Make sure you have a default timezone set somewhere. You could have a separate date_default_timezone_set('America/Sao_Paulo'); call at the top of application_top.php files, or just make sure some default such as 'America/Sao_Paulo' gets set before always calling date_default_timezone_set($visitors_timezone);, if nothing else. Think about how you're going to map the proper timezone if you're only given the language -- for example, the US has at least a half dozen timezones. You might be able to get the IP address of the incoming request and map that better than you could a language. Also be aware that osC lets the browser's language flag override whatever you or your visitor set as the default.

Posted

You definitely don't want date_default_timezone_set() in the line that formats the date! You obviously don't understand what that call is for. It just sets a global setting for time and date calls, and belongs somewhere in the application_top.php files. If you want to give a different timezone setting for each language, you'd have to add some code after where the site language is determined (such as from the browser language setting) and map that to a proper timezone string before calling date_default_timezone_set(timezone name). Make sure you have a default timezone set somewhere. You could have a separate date_default_timezone_set('America/Sao_Paulo'); call at the top of application_top.php files, or just make sure some default such as 'America/Sao_Paulo' gets set before always calling date_default_timezone_set($visitors_timezone);, if nothing else. Think about how you're going to map the proper timezone if you're only given the language -- for example, the US has at least a half dozen timezones. You might be able to get the IP address of the incoming request and map that better than you could a language. Also be aware that osC lets the browser's language flag override whatever you or your visitor set as the default.

 

Hi MrPhill, thank you for replying to my questions, i know it's quite newbish but we have to ask to know. Regarding the date_default_timezone_set() call i understand its logic although it may not appear lol i'm just trying to fix the E_STRICT Errors.

 

How did i sort this? (thanks to your reply i came up with another solution):

 

In catalog/includes/aplication_top.php

 

In the Begin of file immediatly After

// start the timer for the page parse time log
 define('PAGE_PARSE_START_TIME', microtime());

 

Added:

//BOF code added WMF (With My Fix) set timezone
date_default_timezone_set('myzone');
//EOF code added WMF set timezone

 

where myzone is a correct parameter (just google for timezones parameters on date_default_timezone_set().

 

RESULTS:

I have the footer now as it should be and date_default_timezone_set('myzone') is being declared in application_top php sitewide for mycountry, and i dont have any E_STRICT Errors in KissErrorHandler debuguer.

 

QUESTIONS:

In a multilanguage shop environment, clients will see myzone defined in application_top.php, or their IP / or flag overrides regardless of where they come?

Will SQL store the data properly, i.e in system timezone, or in the store time zone defined in application_top regardless of where IP is?

 

Some of this questions may seem to obvious but i appreciate the answers you gave already.

 

Cheers

Posted

Did you only add the one fixed timezone, or did you add more based on some criteria? If just the one, everyone will see your local date and time (your timezone). It has nothing to do with the database -- it just tells PHP to calculate the correct time and date based on your timezone. What else did you do to give your customers their own correct timezone? osC by itself is not going to do anything to change the displayed time.

 

As I said before, you need to figure out a way to map some information about your visitors to their correct timezone, and call date_default_timezone_set() with that timezone, to override your own setting. I don't think the language, or even language+country will help all that much, as many countries span multiple timezones. There are services which map IP addresses to countries or parts of countries -- they might be able to give you enough information to set the proper timezone.

 

If you don't mind unregistered "window shoppers" browsing your store with your timezone showing, you could perhaps add something to ask them their timezone (from a pulldown list) when they create an account. This new field would be added to the customer database. When they sign on, date_default_timezone_set() is called with their correct timezone. Most forums do it this way -- guests (unregisterd browsers) see a common time, but signed-on members get the correct time that they specified when they signed up.

Posted

Hi,

 

Well, i added the fix, it's a very good point in that unregisted customers may not get their own timezones.

 

On the other hand since for now shop has a central in myzone, regardless of it being international, when someone checks will see the default time zone declared, and not his own only in like 2% of cases... i have searched and there isn't a contribution for this, seems people who needed it figured for themselves. I'm good with this fix since clients won't avoid buying just because the timezone is not theirs, and the target client that visits is like 98% of times on the timezone i stipulated in coding.

 

:) sorted &Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...