Show date/time and time zones.

9 posts by 4 authors in: Forums > CMS Builder
Last Post: January 29, 2010   (RSS)

By rconring - January 15, 2010 - edited: January 15, 2010

I am using CMS builder to list radio shows for a website. There is a listing page split into 2 filtered viewers, upcoming shows and past shows archive. Each listing has a show page that details the show, topic, guests etc. Also on the page is an iframe which lets the user hear the live stream during broadcast time (Sat 9:30am - 10:00am EST and Sun 10:00am - 10:30am EST) if clicked.

The station provides an audio file which can be played in the archived listings. On the detail page, I use a PHP conditional to only show the mp3 player object code if a field (show_player) is checked after show is aired in the listing db. (show_date + 30min)

What I would like to do is, based on show date/time, conditionally display either the live stream link or the mp3 player object. The problem I am having with my limited knowledge is accomodating the difference in the users time zone and the syntax for accomplishing the conditional statement.

Here is the listing code which roughly filters future and past shows:

list($future_radio_showRecords, $radio_showMetaData) = getRecords(array(
'tableName' => 'radio_show',
'where' => 'hidden="0" and show_date >= (NOW() - INTERVAL 1 DAY)',
));

list($past_radio_showRecords, $radio_showMetaData) = getRecords(array(
'tableName' => 'radio_show',
'orderBy' => 'show_date DESC',
'where' => 'hidden="0" and show_date < (NOW() - INTERVAL 1 DAY)',
));

Condition to display player object on detail page:
<?php if ($radio_showRecord['audio_filename']): ?>
<?php if ($radio_showRecord['show_player']): ?>
/ ******** Object wrapper here *******/
<?php endif ?>
<?php endif ?>

Thanks in advance ....
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [rconring] Show date/time and time zones.

By Dave - January 18, 2010

Hi Ron,

Are you able to post an example url?

And do you need to take the users timezone into account? Meaning does the show play at the same time everywhere or does it play in different markets and timezones at different times?

And what parts of the code aren't working? The part that loads the future shows, past shows, or the iframe that plays the live stream?

Let me know some more details or pick one part that isn't working if you can and I'll do my best to help!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Show date/time and time zones.

By rconring - January 21, 2010

Dave ...

Looking back, I don't know why I even posted the listing viewer code. That is all working fine ... properly places the past and future shows in their respective lists.

What I should have made clearer is that the code on the detail page currently displays both the iframe for the live stream and conditionally (using a false/true checkbox field in admin) to display the player object after the show airs.

I would like the player object to display automatically a few minutes after the end of the show (show_start_time + 30) rather than have to do it manually with the "show player" in admin.
So the pseudo code would need to be something like:

If current time <= (show_start_time + 30) // --- This is the line of code I need in proper syntax.
display stream iframe
else
display player object
endif

What I am confused about is what time all of this is based upon, broadcast time, server time, or user time.
The 30 minute show airs from the Eastern Time Zone (Sat 9:30 - 10:00 am EST and Sun 10:00 - 10:30 am EST) but server is in Central time Zone.

Does any of this make sense?
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [rconring] Show date/time and time zones.

By Chris - January 22, 2010

Hi Ron,

Luckily you won't have to worry about user time, just broadcast and server time.

I think the easiest way to figure this out would be to print out how much time the server thinks has elapsed since show_start_time:

<?php $elapsedSeconds = time() - strtotime($record['show_start_time']) ?>
Elapsed Seconds since show_start_time: <?php echo $elapsedSeconds ?><br />


Now create a record with a show_start_time set to the current date and time and check that page. If you're quick and everything is working normally, you should see a small number. Refreshing, you should see that number climb up as more time passes.

If instead, you see a number that's off by a multiple of 3600 (60*60 seconds in an hour,) let me know what it is and we can go from there.

Assuming everything's working, your IF block becomes:

<?php $elapsedSeconds = time() - strtotime($record['date']); ?>
<?php $halfAnHourInSeconds = 60*30; ?>
<?php if ($elapsedSeconds > $halfAnHourInSeconds): ?>
display steam iframe
<?php else: ?>
display player object
<?php endif ?>


I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Show date/time and time zones.

By rconring - January 25, 2010

Chris ...

Thanks so much for your time ... so to speak. That got me headed in the right direction. I am still tweaking it, but for the most part, it is working!

Thanks again and have a great day!
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [gkornbluth] Show date/time and time zones.

By rconring - January 25, 2010

Yes, Jerry. I intend to post the full solution as soon as I get it tweaked to work like I want it to. Chris provided me with the info I need to do that ... just trying to get the time.
By the way, thanks for the CMS Cookbook. As a newbie to PHP and MySQL it has been a tremendous help.
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [chris] Show date/time and time zones.

By rconring - January 28, 2010

OK Chris, I am back to this project.
The listing page code for the future and past shows worked fine ... it was the show detail page that gave me the problem.
The code you provided did the trick. It took me a while to implement it because I was distracted by all the code for the player object and the streaming iframe.
I moved those chunks of code to includes to reduce the confusion and here is the final code:

<?php $elapsedSeconds = time() - strtotime($radio_showRecord['show_date']); ?>
<?php $halfAnHourInSeconds = 60*30; ?> - Half hour show
<?php if ($elapsedSeconds > $halfAnHourInSeconds): ?> - If past end of show
<?php if ($radio_showRecord['audio_filename']): ?> - If audio filename present
<?php include('phpincludes/showpage/player_object.php'); ?> - Include the player object code
<?php endif ?>
<?php else: ?> - Else not past end of show
<?php include('phpincludes/showpage/live_stream.php'); ?> - Include the live stream code
<?php endif ?>

Here is the listing page (Excuse the appearance, we are in the process of a complete redesign)
http://happytrailsfarm.org/show_listing.php

Once again, thanks for your help!
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [rconring] Show date/time and time zones.

By Chris - January 29, 2010

Great to hear you've got this working! :D

Please let us know if you have any other questions.
All the best,
Chris