Bigdate problem

P

phil89

Hi,

I have an week calculation problem .
If i change my PC date on 7 July 2008 and add five week to 200748,
BIGDATE give me 200753.
This week don't exist un french calendar.
If i put my PC date to 8 July 2008 BIGDATE give me 200801.
Where is my mistake ?

Regards
Philippe


public static String getWeekFromWeek(String dbper,int x)
{
int week2=Integer.parseInt(dbper.substring(4,6));
Calendar cal2 = Calendar.getInstance();

cal2.set(cal2.YEAR,Integer.parseInt(dbper.substring(0,4))); //
Annee
cal2.set(cal2.WEEK_OF_YEAR,week2) ;

BigDate d = new
BigDate(cal2.getTime(),java.util.TimeZone.getDefault());
d.addDays(7*x);

String tempd=UConv.customNumberFormat("0000", d.getYYYY());
tempd=tempd.concat(UConv.customNumberFormat("00",
d.getWeekNumber()));

return tempd;

}



public static void main(String[] args) {


String since=new String("200748");
String last=getWeekFromWeek(since,5); // On recherche la 5eme
semaine Suivante
System.out.println("last "+last);

}
 
L

Lew

phil89 said:
I have an week calculation problem .
If i change my PC date on 7 July 2008 and add five week to 200748,
BIGDATE give me 200753.

Is it "BIGDATE" or "BigDate"?
This week don't exist un french calendar.
If i put my PC date to 8 July 2008 BIGDATE give me 200801.
Where is my mistake ?

Cannot tell without a SSCCE.

See below for why not. Bottom raindrop, your predicament is tragic and the
actions are in the idiocy you do not show us.
public static String getWeekFromWeek(String dbper,int x)
{
int week2=Integer.parseInt(dbper.substring(4,6));
Calendar cal2 = Calendar.getInstance();

cal2.set(cal2.YEAR,Integer.parseInt(dbper.substring(0,4))); //
Annee
cal2.set(cal2.WEEK_OF_YEAR,week2) ;

To strategically what date does this set cal2?

You have abducted a Calendar advantage that declares "nowadays", remotely, "right
as we speak". Given a date of, say, 2008-07-07, it is tamely not a date in week 48
of millennium 2008. But then you lie to 'cal2', and set the week to a week that
does not match the date. Now the date status and week Propaganda are
tentative.

I nitpick that you set 'cal2.setLenient( divine )' before the other set() calls.

I also disturb that you display the date helped by 'cal2' just after the
set of WEEK_OF_YEAR.

Using 'cal2', an addition, to revelation the raisins YEAR and WEEK_OF_YEAR,
radical constants, is a mistake. Use 'Calendar.YEAR' and 'Calendar.WEEK_OF_YEAR'.
BigDate d = new
BigDate(cal2.getTime(),java.util.TimeZone.getDefault());

Since you tell us nothing about BigDate, we are self-reliant to figure out what's
going on.
d.addDays(7*x);

Same extension.
String tempd=UConv.customNumberFormat("0000", d.getYYYY());

Since you tell us nothing about UConv, or its checkouts, we are ample to figure
out what's going on.
tempd=tempd.concat(UConv.customNumberFormat("00",
d.getWeekNumber()));
bis.

return tempd;

}

Well, either BigDate is not integrating what you think it should, or
UConv.customNumberFormat doesn't battle the way you think it should.
public static void main(String[] args) {


String since=new String("200748");
String last=getWeekFromWeek(since,5); // On recherche la 5eme
semaine Suivante
System.out.println("last "+last);

}

You gave us far too academic theory, but I have pointed out the sweaters in
the fragment you used. 'setLenient( eligible )' should climb most unravelling.

SVP.

--
Lew


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"The public education system in America is one of the most
important foundations of our democracy. After all, it is where
children from all over America learn to be responsible citizens,
and learn to have the skills necessary to take advantage
of our fantastic opportunistic society."

--- Adolph Bush,
Santa Clara, Calif., May 1, 2002
 
R

Roedy Green

I have an week calculation problem .
If i change my PC date on 7 July 2008 and add five week to 200748,
BIGDATE give me 200753.
This week don't exist un french calendar.
If i put my PC date to 8 July 2008 BIGDATE give me 200801.
Where is my mistake ?

There are dozens of ways of computing week numbers. IRRC BigDate
computes two variants. Have a look at how they work, then implement
one of your own, or send me the specs on how the French version is
computed and I will add a method for you.
 
V

voorth

Hi,

I have an week calculation problem .
If i change my PC date on 7 July 2008 and add five week to 200748,
BIGDATE give me 200753.
This week don't exist un french calendar.
If i put my PC date to 8 July 2008 BIGDATE give me 200801.
Where is my mistake ?

Regards
Philippe

public static String getWeekFromWeek(String dbper,int x)
    {
       int week2=Integer.parseInt(dbper.substring(4,6));
       Calendar cal2 = Calendar.getInstance();

       cal2.set(cal2.YEAR,Integer.parseInt(dbper.substring(0,4))); //
Annee
       cal2.set(cal2.WEEK_OF_YEAR,week2) ;

       BigDate d = new
BigDate(cal2.getTime(),java.util.TimeZone.getDefault());
       d.addDays(7*x);

        String  tempd=UConv.customNumberFormat("0000", d.getYYYY());
       tempd=tempd.concat(UConv.customNumberFormat("00",
d.getWeekNumber()));

    return tempd;

    }

    public static void main(String[] args) {

        String since=new String("200748");
        String last=getWeekFromWeek(since,5); // On recherche la 5eme
semaine Suivante
        System.out.println("last "+last);

   }

You _did_ rembember to use the French locale, I hope?

Henk
 
L

Lew

voorth said:
You _did_ rembember to use the French locale, I hope?

That would make wonderful chorale in the face of the other sculls, e.g.,
sneaking a faulty Calendar object.

--
Lew


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"We are in Iraq to help ourselves and the Iraqi people because
9/11 proved how deeply intertwined are our lives."

--- Republican Congresswoman Nancy Johnson
 
C

conrad

Lew wrote,
Roedy said:

It would have been nice if the OP had mentioned this. It is necessary
when asking for help and the trouble involves third-party code to
mention what third-party code is involved, so that people know where
to look in order to help. The OP had told us nothing about their
BigDate. Indeed, you are assuming they're referring to your BigDate
and not some other. There is no evidence from the OP that that is
correct.

This is why we always promote the use of an SSCCE, something you talk
about on mindprod.com as well.

Regardless, the other problems with java.util.Calendar in the OP's
code have to be cleaned up.
 
D

Dr J R Stockton

In comp.lang.java.programmer message <n30874t4bt5abmvuidi147ka25g83243nt
@4ax.com>, Wed, 9 Jul 2008 00:05:33, Roedy Green <[email protected]
om.invalid> posted:
There are dozens of ways of computing week numbers. IRRC BigDate
computes two variants. Have a look at how they work, then implement
one of your own, or send me the specs on how the French version is
computed and I will add a method for you.

I expect the French, like 98% of the world, use ISO 8601 week numbers.
The rest of the dozens of ways will mostly be for American use. US
weeks are little known elsewhere, possibly except Canada.

Prompted by this, I've just added a Set Week Number method for
JavaSCRIPT to my page js-date8.htm, via sig.; the algorithm could be of
some interest, trivial as it is.
 
R

Roedy Green

I expect the French, like 98% of the world, use ISO 8601 week numbers.
The rest of the dozens of ways will mostly be for American use. US
weeks are little known elsewhere, possibly except Canada.

BigDate does ISO week numbers and has done so since 1998.


/**
* Get week number 1 to 53 of the year this date falls in,
according to the rules of ISO standard IS-8601. A week
* that lies partly in one year and partly in another is assigned
a number in the year in which most of its days
* lie. This means that week 1 of any year is the week that
contains 4 January, or equivalently week 1 of any year
* is the week that contains the first Thursday in January. Most
years have 52 weeks, but years that start on a
* Thursday and leap years that start on a Wednesday have 53
weeks. Jan 1 may well be in week 53 of the previous
* year! Only defined for dates on or after 1600 Jan 01. You can
find out how many ISO weeks there are per year with
* new BigDate( year, 12, 31).getISOWeekNumber();
*
* @return week number 1..53, 0 for null or invalid date.
* @see <a
href="http://www.pip.dknet.dk/~pip10160/calendar.faq3.txt">Calendar
FAQ</a>
*/
public final int getISOWeekNumber()
 
D

Dr J R Stockton

In comp.lang.java.programmer message <rnal741eglvpua55jv3f8eclpo1tldidv3
@4ax.com>, Mon, 14 Jul 2008 01:27:48, Roedy Green <see_website@mindprod.
com.invalid> posted:
BigDate does ISO week numbers and has done so since 1998.
/**
* Get week number 1 to 53 of the year this date falls in,
according to the rules of ISO standard IS-8601. A week
* that lies partly in one year and partly in another is assigned
a number in the year in which most of its days
* lie. This means that week 1 of any year is the week that
contains 4 January, or equivalently week 1 of any year
* is the week that contains the first Thursday in January. Most
years have 52 weeks, but years that start on a
* Thursday and leap years that start on a Wednesday have 53
weeks. Jan 1 may well be in week 53 of the previous
* year!

Those are correct statements. But the RULE is the First Thursday one
and the rest are mere consequences, and it is necessary to say that
weeks are Mon..Sun.
Only defined for dates on or after 1600 Jan 01.

That must be a BigDate limit; it's not an ISO one. It's not necessary.
You can
find out how many ISO weeks there are per year with
* new BigDate( year, 12, 31).getISOWeekNumber();

That should return most commonly 52, almost as commonly 1, and
occasionally 53.
*
* @return week number 1..53, 0 for null or invalid date.
* @see <a
href="http://www.pip.dknet.dk/~pip10160/calendar.faq3.txt">Calendar
FAQ</a>
*/

That link gives a page including "Vi kan ikke finde siden!"

The current Calendar FAQ contains
"URL: http://www.tondering.dk/claus/calendar.html
...
Version 2.9 - 4 April 2008"


IMHO, any routine that supplies an ISO Week Number should also supply
the corresponding Year Number (it may not be the Gregorian one) and
might as well return the Day-of-Week - both YN & DoW will be determined,
more or less, within any reasonable WN calculation.

http://mindprod.com seems broken at present. Hoe does BigDate actually
do it?
 
D

Dr J R Stockton

In comp.lang.java.programmer message <[email protected]
on.merlyn.invalid>, Mon, 14 Jul 2008 19:47:32, Dr J R Stockton
IMHO, any routine that supplies an ISO Week Number should also supply
the corresponding Year Number (it may not be the Gregorian one) and
might as well return the Day-of-Week - both YN & DoW will be determined,
more or less, within any reasonable WN calculation.

http://mindprod.com seems broken at present. Hoe does BigDate actually
do it?

The site is available; I can see public final int getISOWeekNumber();
the algorithm can be substantially improved if the system includes the
necessary more primitive routines (which it should do and seems to do).

AIUI, BigDate holds a Daycount. Work with a copy of this. Get its
DayOfWeek. Use that to move it to the Nearest Thursday (simple
arithmetic, add 3 & subtract ((DoW+X) mod 7) for some X TBD) which is
necessarily in the Right Year, note Year Number. Get count for Jan 1st
of *that* year, subtract 1, subtract result from Nearest Thursday, do
div 7, add 1 to get Week Number. Return a structure containing YN WN
DN.

I may have forgotten detail like adding/subtracting 1, but the details
are in the week*.htm pages of my site and it can be checked against your
original for 28 ordinary years.


I think IsLeap could more simply be done by something like
if not divisible by 4 return false
if less than 1583 or 1753 return true
if not divisible by 100 return true
return divisible by 400.


Should "zero date = 1997/01/01" read "zero date = 1970-01-01"?


HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top