NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 35 36 37 38 39 … 93 Next »
Modified Julian Date

 
  • 0 Vote(s) - 0 Average
Modified Julian Date
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#1
2008-02-10, 07:19 PM
The date carried for EPG info in a DVB broadcast is encoded as a Modified Julian Date. The document I have gives the following formulae to convert to Year, Month and Day components.

Quote:a) To find Y, M, D from MJD

Y' = int [ (MJD - 15 078,2) / 365,25 ]
M' = int { [ MJD - 14 956,1 - int (Y' × 365,25) ] / 30,6001 }
D = MJD - 14 956 - int (Y' × 365,25) - int (M' × 30,6001)
If M' = 14 or M' = 15, then K = 1; else K = 0
Y = Y' + K
M = M' - 1 - K × 12
The following is my C# interpretation but my day result is always one day ahead, i.e., today is the 10th but my code is returning D=11.
Code:
int MJD = (start_time[0] * 256) + start_time[1];
int Y1 = Convert.ToInt32((MJD - 15078.2) / 365.25);
int M1 = Convert.ToInt32((MJD - 14956.1 - Convert.ToInt32(Y1 * 365.25)) / 30.6001);
int D = MJD - 14956 - Convert.ToInt32(Y1 * 365.25) - Convert.ToInt32(M1 * 30.6001);
int K = 0;
if ((M1 == 14) || (M1 == 15))
        K = 1;
int Y = Y1 + K;
int M = M1 - 1 - (K * 12);

Console output:
Quote:MJD: 54506 Y1: 108 M1: 3 K: 0 Y: 108 M: 2 D: 11
Can anybody see what's wrong with my code.

Cheers,
Brian
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,789
Threads: 769
Joined: Nov 2003
#2
2008-02-10, 08:05 PM
Your calculation is pretty similiar to mine. My last line is the equivalent of "int M = M1 - 2 - (K * 12);" though. Your first line is also different a different to how I get the mjd value.
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#3
2008-02-10, 09:39 PM
The start_time array contains the 5 bytes of the start_time field in the present/following EIT section. I've taken the MJD value and plugged it into an MJD converter web site and it happily tells me it's 10/2/2008. All I can think is that there's a typo in the ETSI document where I got the formula (i.e., D should be blah - 1). The year and month are right - just the day is wrong. Oh well.

Cheers,
Brian
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,789
Threads: 769
Joined: Nov 2003
#4
2008-02-10, 09:51 PM
Are you sure your problem doesnt relate to the range of the output values. ie months 0-11 vs 1-12, and for day of month etc, which may mean adding or subtracting one when using those values.
Ommina
Offline

Senior Member

Posts: 330
Threads: 39
Joined: Feb 2006
#5
2008-02-11, 01:40 AM
Shot in the dark:

Convert.Int32 will round up to the nearest integer, while the original formula might be expecting the decimal portion to be chopped right off.

Let's try...

Code:
int Y1 = (int) Math.Floor((MJD - 15078.2) / 365.25);
int M1 = (int) Math.Floor((MJD - 14956.1 - Math.Floor(Y1 * 365.25)) / 30.6001);
int D = (int) (MJD - 14956 - Math.Floor(Y1 * 365.25) - Math.Floor(M1 * 30.6001));
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#6
2008-02-11, 03:39 AM
Quote:Convert.Int32 will round up to the nearest integer
I was beginning to suspect that and tried a test of Convert.Int32(39 / 10) which returned the value 3 and not 4 which I'd expect from rounding up.
Quote:while the original formula might be expecting the decimal portion to be chopped right off.
Yes, that's what is expected.

Quote:Let's try...

Code:
int Y1 = (int) Math.Floor((MJD - 15078.2) / 365.25);
int M1 = (int) Math.Floor((MJD - 14956.1 - Math.Floor(Y1 * 365.25)) / 30.6001);
int D = (int) (MJD - 14956 - Math.Floor(Y1 * 365.25) - Math.Floor(M1 * 30.6001));
Perfect - thanks! My debug output now shows...
Quote:MJD: 54507 Y1: 107 M1: 15 K: 1 Y: 108 M: 2 D: 11
This is what I was getting with a pen, paper and a calculator. Computers huh!? Never trust them. Big Grin

I'll make sure I remember the Math class in future.

Cheers,
Brian
Ommina
Offline

Senior Member

Posts: 330
Threads: 39
Joined: Feb 2006
#7
2008-02-11, 06:41 AM
bgowland Wrote:I was beginning to suspect that and tried a test of Convert.Int32(39 / 10) which returned the value 3 and not 4 which I'd expect from rounding up.

Computers huh!? Never trust them. Big Grin

/grin

And if you REALLY want to spend the evening quietly crying in the corner, try Convert.Int32(39.0 / 10.0) instead. Since 39 and 10 are both integers to start with, it is returning an (truncated) integer for your comfort and convenience -- so the Convert gets a three and gives it back.

A little lesson that cost me a lot of hours -- and no small amount of hair.

As you say: Never trust 'em!
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Web Client: Slow with separate thread and date not obscured cncb 32 16,309 2016-10-10, 02:01 PM
Last Post: mvallevand
  Date Time display Northpole 0 1,479 2011-08-01, 04:28 PM
Last Post: Northpole
  Suppressing the Date/Time field from global.xml ACTCMS 7 3,321 2010-11-18, 01:36 AM
Last Post: ACTCMS
  Supress Date display in NPVR skin Northpole 13 4,281 2010-10-02, 08:19 PM
Last Post: Northpole
  .net / sqlite3 Date Types... zehd 4 4,713 2008-03-25, 01:36 AM
Last Post: zehd
  @time and @date not updating Digital712 3 2,113 2006-08-23, 02:06 AM
Last Post: Fatman_do
  Date formatting in skins dinki 4 2,073 2006-03-29, 08:55 PM
Last Post: Jeff
  Can the MediaMVP DirectShow graph be modified from a plugin? jmemmott 0 1,312 2005-05-30, 07:33 PM
Last Post: jmemmott

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode