UTC Dates Out -> Local Time In? (1 Viewer)

ChubbyArse

Portal Member
December 28, 2011
40
1
Hi all, I'm using MPExtended to drive a plugin to link MediaBrowser and Media Portal. I'm in a GMT timezone, so everything is good - however there is a user in Germany (UTC+1) that is having trouble creating a schedule.

At the point I create the REST call - I read the data out of MPExtended for the program to ensure that I get the right time for the schedule and create something like this:

http://192.168.0.3:4322/MPExtended/TVAccessService/json/AddScheduleDetailed?channelid=92&title=Grimm [2]&starttime=2014-12-15T21:10:00&endtime=2014-12-15T22:05:00&scheduletype=0&preRecordInterval=5&postRecordInterval=10

(Hmmmm..... I have just noticed that I should probably URLEncode the string!)

The problem is that in local time the program details are Monday, 15. December at 22.10 - 23.05 pm. I assumed that as UTC dates come out of MPExtended - I would send back UTC dates, but the experience of this user suggested otherwise?

So, I wanted to confirm that although MPExtended returns UTC data, you need to use local times when passing back to MPExtended? So a simple .ToLocalTime() should do it....

Thanks
 

johanj

MP Donator
  • Premium Supporter
  • January 31, 2009
    781
    398
    46
    Home Country
    Sweden Sweden
    Hi

    It's been a while since I made the date/time parts for tv. Checking through the javascript code I see that the time should be given in ISO_8601 format for MPExt. In javascript I use the below conversion methods. When recording a program with 'AddScheduleDetailed' I use this to get the time string for 'startTime and 'endTime':

    self.getISODateString(self.getDateFromMPDateTime(data.StartTime))

    data.StartTime is in the response from 'GetProgramBasicById'

    Hope this helps.

    Btw, I have not really used your MB3 plugin yet so I can't give you much test results. Channels are in correct order now. Several times the I get messages that MB3 server couldn't get the tv data. I noticed that the MB3 server log has a lot of exceptions from your plugin. I can upload it later.


    Johan

    Code:
    self.getDateFromMPDateTime = function(dateTime) {
            try {
                return new Date(parseInt(dateTime.substring(6, 24)));
            } catch (e) {
                CF.log("Exception caught while creating Date: " + e);
                return "date error";
            }
        };
    
        self.getDateFromISOTime = function(dateString) {
            var ISO_8601_re = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/;
            var m = dateString.match(ISO_8601_re);
    
            var year = +m[1];
            var month = +m[2];
            var dayOfMonth = +m[3];
            var hour = +m[4] - 1;
            var minute = +m[5];
            var second = +m[6];
    
            var myDate = new Date();
            myDate.setUTCFullYear(year);
            myDate.setUTCMonth(month - 1);
            myDate.setUTCDate(dayOfMonth);
            myDate.setUTCHours(hour);
            myDate.setUTCMinutes(minute);
            myDate.setUTCSeconds(second);
    
            return myDate;
        }
    
    self.getISODateString = function ISODateString(d) {
            var d2 = new Date(d.getTime());
            return d2.toISOString();
        };
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    ...and in case it helps, internally the TV Server database works entirely with local dates/times. If you're getting UTC dates/times out then I'd guess that MPExtended is applying conversions, and I couldn't say what the correct procedure would be for saving back.
     

    ChubbyArse

    Portal Member
    December 28, 2011
    40
    1
    Thanks for the responses. I changed my C# code to use .ToLocalTime() on the dates and it seemed to fix the issue when creating schedules (passing dates back into MPExtended). There's a user in Germany (UTC+1) that gets the correct dates set whilst I do in the UK too (UTC+0).

    johanj - could you retry please with the latest beta version 0.1.0.34902 (you'll need to change your MB3 install to "Beta" and install from the catalog). There was a breaking change a while back in the core server which could have caused the error logs you mention. Let me know how you get on. This is likely to form a v1 release for production.

    Thanks
     

    johanj

    MP Donator
  • Premium Supporter
  • January 31, 2009
    781
    398
    46
    Home Country
    Sweden Sweden
    Changed to MB3 beta and reinstalled your plugin an hour ago. Restarted server and configured the plugin, restarted again. The epg filled but all streams failed. Tested now again and it all works. I report back if I get issues.
     

    ChubbyArse

    Portal Member
    December 28, 2011
    40
    1
    Thanks for the feedback johanj - I'd be interested to see the logs for the time that your streaming failed.

    I have a feeling it could have been the configuration screen - it's not straightforward as you have to enter the MPExtended connection details (api hostname / authentication etc) before you can retrieve the channel groups and streaming profiles. What this requires the user to do is enter the connection details, then save. Then go back into the screen to select the channel group streaming profile. This is isn't immediately obvious - so I'll try to smooth out the experience and then other users hopefully won't have the same issue.

    Do you think this could be similar to your experience, or had you fully selected everything in the configuration screen before you had streaming issues?

    Thanks
     

    Users who are viewing this thread

    Top Bottom