From: phil89 on
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);

}
From: Lew on
phil89 wrote:
> 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 an SSCCE.
<http://pscode.org/sscce.html>

See below for why not. Bottom line, your example is incomplete and the
problems are in the part 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 exactly what date does this set cal2?

You have created a Calendar instance that represents "today", actually, "right
now". Given a date of, say, 2008-07-07, it is certainly not a date in week 48
of year 2008. But then you lie to 'cal2', and set the week to a week that
does not match the date. Now the date information and week information are
inconsistent.

I recommend that you set 'cal2.setLenient( false )' before the other set() calls.

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

Using 'cal2', an instance, to reference the fields YEAR and WEEK_OF_YEAR,
static 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 unable to figure out what's
going on.

> d.addDays(7*x);

Same observation.

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

Since you tell us nothing about UConv, or its methods, we are unable to figure
out what's going on.

> tempd=tempd.concat(UConv.customNumberFormat("00",
> d.getWeekNumber()));

bis.

> return tempd;
>
> }

Well, either BigDate is not constructing what you think it should, or
UConv.customNumberFormat doesn't convert 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 little information, but I have pointed out the errors in
the fragment you provided. 'setLenient( false )' should prove most illuminating.

<http://pscode.org/sscce.html>
SVP.

--
Lew
From: Roedy Green on
On Mon, 7 Jul 2008 23:28:44 -0700 (PDT), phil89 <pcouas(a)infodev.fr>
wrote, quoted or indirectly quoted someone who 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.
>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.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
From: Roedy Green on
On Tue, 08 Jul 2008 03:15:06 -0400, Lew <lew(a)lewscanon.com> wrote,
quoted or indirectly quoted someone who said :

>Since you tell us nothing about BigDate, we are unable to figure out what's
>going on.

see http://mindprod.com/products1.html#BIGDATE
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
From: Lew on
phil89 wrote:
> 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