mde / timezone-js

DEPRECATED: Timezone-enabled JavaScript Date object. Uses Olson zoneinfo files for timezone data.
824 stars 183 forks source link

Can't load timezone with JQuery. #50

Closed codefuze closed 11 years ago

codefuze commented 11 years ago

I am trying to get this to work with JQuery. I get the following error:

Uncaught Error: Timezone "America/Chicago" is either incorrect, or not loaded in the timezone registry.

The readme states I would need too create a custom transport method. Could anyone give an example on how I would do this or create a wiki for it. Sorry to create an issue, this has been driving me crazy!

longlho commented 11 years ago

can u post a code snippet? You have to specify tz lib data with

timezoneJS.timezone.zoneFileBasePath = '/tz';
timezoneJS.timezone.defaultZoneFile = ['asia', 'backward', 'northamerica', 'southamerica'];
timezoneJS.timezone.init();

as specified in the docs. Let me know if it doesn't work.

codefuze commented 11 years ago

I have specified the data. Here is a code snippet:

<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/timezone-js/src/date.js"></script>
<script>
$(document).ready(function(){
    timezoneJS.timezone.zoneFileBasePath = 'tz';
    timezoneJS.timezone.defaultZoneFile = ['northamerica'];
    timezoneJS.timezone.init();
    /*** My Code Here ***/
    var ct = new timezoneJS.Date(year, month, day, hours, mins, 'America/Chicago');
});
</script>

It will not load the data. Any thoughts?

longlho commented 11 years ago

Oh try turning off async with init({async: false}). Otherwise you'll need a callback.

Long Ho Web Developer iHeartRadio/Clear Channel Radio

On Nov 23, 2012, at 6:05 PM, codefuze notifications@github.com wrote:

I have specified the data. Here is a code snippet:

It will not load the data. Any thoughts?

— Reply to this email directly or view it on GitHub.

codefuze commented 11 years ago

Thanks! That was it.

onassar commented 11 years ago

+1 Worked great for me.

BrunoWinck commented 10 years ago

Same here, without it this sample won't work, glad I reached this page

timezoneJS.timezone.zoneFileBasePath = path.join( __dirname, 'tz'); timezoneJS.timezone.loadingScheme = timezoneJS.timezone.loadingSchemes.PRELOAD_ALL; timezoneJS.timezone.init({async: false}); console.log( timezoneJS.timezone.zoneFiles.length); <- this would be 10 even if it is not yet loaded and available var dt = new timezoneJS.Date(2013, 0, 1, 'America/Juneau'); console.log( dt);

longlho commented 10 years ago

just added clarification to the README :) Hope that helps

lucasboko commented 9 years ago

Hi all,

I keep getting this in my console while using timezone.js :

warning : Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.

error: GET http://exodo/tz/asia 404 (Not Found)

error : Uncaught TypeError: Cannot read property '1' of null

// code snipet timezoneJS.timezone.zoneFileBasePath = 'tz'; timezoneJS.timezone.defaultZoneFile = ['asia', 'backward', 'northamerica', 'southamerica']; timezoneJS.timezone.init({ async: false }); var dt = new window.timezoneJS.Date(new Date()); console.debug(dt.toString()); dt.setTimezone('America/Los_Angeles'); alert(dt);

lucasboko commented 9 years ago

Just found the solution. The list of Olson files where missing in /tz folder.