### JulianType problem

Thu, 05/31/2007 - 03:30

### Forums:

We are encountering a problem while converting from JulianType to seconds and then back to JulianType.

After some effort it was evident that the BREW helpers JULIANTOSECONDS and GETJULIANDATE are to be blamed.

When we try to convert the seconds back to the JulianType using GETJULIANDATE then it results in incorrect values.

We also tested this on a sample application (HelloWorld) and the results are the same.

Here is the code snippet:

void TestJulianType()

{

/** This function is written for debug test of the Julian Conversion */

uint32 julSeconds = 0;

JulianType julType, newJulType;

julType.wYear = 2500;

/* Also in case of 1500 it results in an absurd value on conversion back to JulianType */

julType.wMonth = 1;

julType.wDay = 1;

julType.wHour = 0;

julType.wMinute = 0;

julType.wSecond = 0;

julSeconds = JULIANTOSECONDS(&julType);

//Till now julSeconds is > 3524618112

GETJULIANDATE( julSeconds, &newJulType);

//After this newJulType is > 2091-9-14 4:35:12

Is there a lower & upper bound for dates that can be addressed using JulianType?

Has anyone observed such a problem before? :confused:

Any tips for avoiding this would be greatly helpful for us.

-Harshal

Thu, 05/31/2007 - 09:50

Thanks Ram, for giving muscle to my frail doubt...

Thanks for the info. :)

-Harshal

Thanks Ram, for giving muscle to my frail doubt...

Thanks for the info. :)

-Harshal

Mon, 09/10/2007 - 20:11

Just F.Y.I. based on some testing that i've ran I think the upper boundary for the date is Feb. 6, 2116.

Could somebody confirm these please?

Thank You and Good Day.

Just F.Y.I. based on some testing that i've ran I think the upper boundary for the date is Feb. 6, 2116.

Could somebody confirm these please?

Thank You and Good Day.

Tue, 09/11/2007 - 01:42

Hemlock wrote:Just F.Y.I. based on some testing that i've ran I think the upper boundary for the date is Feb. 6, 2116.

Could somebody confirm these please?

Thank You and Good Day.

I had to do a calendar application which had to support year before 1980 also. There I had encountered this issue initially when I had set the max year to 2200.

I remember it was max date that can be calculated by JULIANtype was around the year 2116

I used this algorithm (googled.. :) ) which was used in calculating the week day of a particular date. It was giving correct values 1900 (which was lowest in the range) and max was set to 2099.

***********************************************************************

Uses zeller's algorithm for finding the day for the date

***********************************************************************

details of algorithm are :-

[x] = floor (x)

Formula for calculating the week day of a day in a year.

f = k + [((13*m)-1)/5] +d + [d/4] + [c/4] - (2*c).

where k=>day of the month.

c=>first two digits of year i.e. number of centuries.

m=>month number. march=1 jan=11 feb=12 etc.

d=>last two digits of year.i.e.year thru centuries.

if (month=Jan or Feb)

if (d=0), then d=99; c=c-1;(jan,feb treated as previous year)

else d=d-1;

Once we get f,divide it by 7 and take remainder.If it is negative add 7.

remainder = day of the week (0=sunday 1=monday 6=saturday etc.)

***********************************************************************

Also remember for JulianType (6=Sunday,0=Monday,....5=Saturday).

Hemlock wrote:Just F.Y.I. based on some testing that i've ran I think the upper boundary for the date is Feb. 6, 2116.

Could somebody confirm these please?

Thank You and Good Day.

I had to do a calendar application which had to support year before 1980 also. There I had encountered this issue initially when I had set the max year to 2200.

I remember it was max date that can be calculated by JULIANtype was around the year 2116

I used this algorithm (googled.. :) ) which was used in calculating the week day of a particular date. It was giving correct values 1900 (which was lowest in the range) and max was set to 2099.

***********************************************************************

Uses zeller's algorithm for finding the day for the date

***********************************************************************

details of algorithm are :-

[x] = floor (x)

Formula for calculating the week day of a day in a year.

f = k + [((13*m)-1)/5] +d + [d/4] + [c/4] - (2*c).

where k=>day of the month.

c=>first two digits of year i.e. number of centuries.

m=>month number. march=1 jan=11 feb=12 etc.

d=>last two digits of year.i.e.year thru centuries.

if (month=Jan or Feb)

if (d=0), then d=99; c=c-1;(jan,feb treated as previous year)

else d=d-1;

Once we get f,divide it by 7 and take remainder.If it is negative add 7.

remainder = day of the week (0=sunday 1=monday 6=saturday etc.)

***********************************************************************

Also remember for JulianType (6=Sunday,0=Monday,....5=Saturday).

Thu, 05/31/2007 - 05:15

Harshal,

There is nothing wrong with JULIANTOSECONDS and GETJULIANDATE, instead there is a limit of Lower and Upper bounds. Lower bound is jan 6 1980 and upper bound is at Year-2116(i don't remember exact date). If you really want to deal with Year-2500, go for an alternative to JulianType.

We haven't faced any problem with JulianType. Seconds for Year-2500 are not in the scope of uint32. The problem is with converting u r date to seconds, not in GETJULIANDATE, 3524618112 is not the correct representation of 01-01-2500.

Thanks,

Ram.

Harshal,

There is nothing wrong with JULIANTOSECONDS and GETJULIANDATE, instead there is a limit of Lower and Upper bounds. Lower bound is jan 6 1980 and upper bound is at Year-2116(i don't remember exact date). If you really want to deal with Year-2500, go for an alternative to JulianType.

We haven't faced any problem with JulianType. Seconds for Year-2500 are not in the scope of uint32. The problem is with converting u r date to seconds, not in GETJULIANDATE, 3524618112 is not the correct representation of 01-01-2500.

Thanks,

Ram.