A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: different timezones for radio schedule......

  1. #1
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242

    different timezones for radio schedule......

    hi, I'm trying to write some code to display a radio schedule.

    I'm playing around with getHour
    Code:
    hour = now.getHour();  
    if hour>6 && hour<9
    program="Breakfast Show";
    else if hour>9 && hour<12
    program="Just After Breakfast Show";
    etc......
    where 'program' is a line of dynamic text..... but I'm not really getting any where

    I've also realised that getHour refers to the system clock and so would only be relevant in the same country where the Radio show is being heard.... is it possible to calculate all times based upon GMT..????

    If anyone's got any ideas on any of this I'd be very grateful..... (pulling hair out time..... again...)

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    All the get/set methods for the Date object have UTC (Universal Time Code) equivalents.

    So you can create a UTC date (for your radio schedule) using setUTCHours(), and then use the non-UTC method getHours() to retrieve the local version of that time to display to the user.

    - Jim

  3. #3
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242
    eek...

    Not at all sure as to where you're coming from with that one... I understand that I have to set the timezone and then offset it in either direction... but I have no idea as where to start...

    I'm still having trouble getting my 'local' time code working
    Code:
    myDate = new Date( year, month, date, hour, min, sec, ms );
    hours = mydate.getHours();
    if (int (hours)>6 && (hours)<9) {
    	program = "Breakfast Show";
    }
    else if (int (hours)>9 && (hours)<12) {
    	program = "Just After Breakfast Show";
    }
    else {
    	program = "PROGRAM SCHEDULE";
    }
    which is butchered code from a clock that I did a very long time ago....

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    If your work in UTC time, then you don't have to figure out the user's timezone. It gets taken care of for you.

    First off, you need to figure what UTC hours your breakfast show actually runs in (this will be the same all over the world). More on that step below.

    Once you've figured out your UTC schedule, things are simpler.

    In the example script you showed above, use getUTCHours() instead of getHours().

    Let's say you figure out that your breakfast show runs from 12-15:00 in UTC hours.

    myDate = new Date( year, month, date, hour, min, sec, ms );
    // or just myDate = new Date() if you want the current time.

    hours = mydate.getUTCHours();
    if (int (hours)>=12 && (hours)<=15) {
    program = "Breakfast Show";
    }
    // etc. etc. etc.


    So the code is basically the same as what you would use locally, but you use getUTCHours(),
    and you have to figure out your UTC schedule.

    To figure out your UTC schedule, make a test movie that does something like this:

    dt = new Date();
    trace("Current hour " + dt.getHours());
    trace("UTC hour " + dt.getUTCHours());
    offset = dt.getUTCHours() - dt.getHours();
    trace("UTC Offset = " + offset);

    From this you can figure out the difference between UTC and local time,and then just add that offset to all the hours in your schedule.

    For example, I live in Los Angeles, and the above script produces the following:

    Current hour 15
    UTC hour 22
    UTC Offset = 7

    So if my breakfast show ran from 9-12 locally, I would program my breakfast show to run from 16-19 based on getUTCHours().

    Hope this helps.

    - Jim
    Last edited by jbum; 09-30-2004 at 06:42 PM.

  5. #5
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242
    Thanks Jim, I'll have a ponder over all this - I've got the schedule, so I know my times, so I guess it's just a case of playing around with this code til I can get something to work.

    Nice one. Thanks for your help

    Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center