baantool
27th March 2002, 19:01
I am confused as to the usage for num.to.week()

The argument for week_dayno says:

"The day of the week. This depends on which day is defined as the first day of the week in the user data settings in the data dictionary in the user data settings in the data dictionary."

One user logs in and gets a date 03-21-02. Another user gets the date 03-22-02. The session is the same, the code is the same. They are both in the same VRC and Company.

I have looked everywhere that I can think of in Baan5, and can't find any table, any user setting, other than Maintain Companies, which would indicate any first day of the week setting.

Can anybody help me out please?

Thanks!
baantool

Darren Phillips
27th March 2002, 19:09
I am guessing but would the locale setting in the user setup affect the date display format.

baantool
27th March 2002, 20:48
To add a little confusion to the mix:

In debug, using the date.num() function and the num.to.week() like so:

num.to.week(date.num(), wkno, yrno, wk, yr)

For the first user:

date.num = 730936
wkno = 3
yrno = 86
wk = 13
yr = 2002

For the second user:

date.num() = 730936
wkno = 4
yrno = 86
wk = 13
yr = 2002

Which leads me further to believe that there is some user-specific setting which determines the day of the week.

Any help is greatly appreciated,
baantool

NPRao
27th March 2002, 22:12
Can you check the user data template, maybe they are linked to 2 different time zones ??

baantool
27th March 2002, 23:04
the time zones for both users are the same.

lvdvelde
5th December 2003, 16:03
Hey everyone,

I experience the same thing:

When I execute:

ret = rdi.first.day.of.week()

than ret = 2 | that's monday

And when I execute:

s.sdat = "29092003" | this is also a monday
sdat = inputstr.to.date(s.sdat, "%D777") | ddmmyyyy
e = num.to.week(sdat, wday, yday, wknm)

than:

sdat = 731487
wday = 1 ????!!!!!!!
yday = 272
wknm = 40

and for checking the right conversion:

e = num.to.date(sdat, year, month, mday)

year = 2003
month = 9
day = 29

Can anybody tell me why monday isn't always day 1?

Greetings, Lex

mark_h
5th December 2003, 16:25
lvdvelde,

rdi.first.day.of.week always assumes Sunday is day 1. Num.to.week works off the company calendar, were monday could be the first day of the week.

As for Baantools problem, I am not aware of any local user settings which may effect this, but will look around.

Mark

lvdvelde
5th December 2003, 17:23
I think the function rdi.first.day.of.week() responds according to domain tcdynm, in which sunday is always day 1.

This explains why the return value of that function is 2, because I have monday parameterized as "the first day of the week".

The function num.to.week() responds the offset in days to the first day of the week as defined in the data dictionary. That's why a monday (date) input results in a weekday = 1.

Now I want to insert this weekday by using AFS in tihra100.dayn.
Every monday in tihra100 is day 2 (domain tcdynm). So the record inserted is one day early. Will somebody please shoot me?

... or tell me what I'm doing wrong?

Lex

mark_h
5th December 2003, 17:56
I guess I do not really understand the problem. I have not done any function servers for any tihra sessions. Are you trying to do a put on tihra100.hrdt (form 2 Date field) and getting some kind of errors or what? Or does it work for just the wrong date?

Mark

lvdvelde
5th December 2003, 18:01
Hi Mark,

I'm trying to put this day value in 2 fields:

stpapi.put.field("tihra1101m100", "tihra100.stdy", str$(wday))
stpapi.put.field("tihra1101m100", "tihra100.endy", str$(wday))

but I think that the tihra1101 function server expects a "2" in these fields when you mean monday. And my num.to.week() function returns a 1 for a monday which cannot be right.

Lex

lbencic
5th December 2003, 20:13
Hi -
If I understand correct, I have had this problem in Hours Accounting - Baan has a standard function for handling this conversion. Week to num will mess you up, if used directly - I know! Here's what I have done, complete with my old version, commented out (which worked great as long as the start day was always Sunday!)


|*rmc.o get.startdate = week.to.num(get.week, get.year, etol(get.stdy))
|*rmc.sn
check.dayn = itihra0001.convert.dayname.to.daynumber(get.stdy)
get.startdate = week.to.num(get.week, get.year, check.dayn)
|*rmc.en


This requires an include of itihra0001, and the source for that. If you do not have the source, you should be able to obtain it from Baan support - they usually are willing to give the source for these support functions out, but that's up to them. If not, it should be fairly easy to duplicate - that dayn enum needs to be change to the proper day of the week based on the calendar as suggested, before you can use it in the date functions, and vice versa. I believe there also exists the function

itihra0001.convert.daynumber.to.dayname, which I think is what you will need to convert the date to the proper enum value before you insert it using the api.

Hope that helps, good luck.

DStroud
5th December 2003, 21:33
Listed below is the code I used to determine the Start and End date for hours accounting.

Start Date
dcs.date.mmddyyyy = trans.image(1;8) | Start date
dat = inputstr.to.date(dcs.date.mmddyyyy,"%D006,2")
return.code = num.to.week(dat,week_dayno,year_dayno,weekno,yearno)
on case week_dayno
case 1:
tihra100.stdy = tcdynm.sunday
break
case 2:
tihra100.stdy = tcdynm.monday
break
case 3:
tihra100.stdy = tcdynm.tuesday
break
case 4:
tihra100.stdy = tcdynm.wednesday
break
case 5:
tihra100.stdy = tcdynm.thursday
break
case 6:
tihra100.stdy = tcdynm.friday
break
case 7:
tihra100.stdy = tcdynm.saturday
break
default:
tihra100.stdy = empty
break
endcase
End Date
dcs.date.mmddyyyy = trans.image(10;8) | stop date
dat = inputstr.to.date(dcs.date.mmddyyyy,"%D006,2")
return.code = num.to.week(dat,week_dayno,year_dayno,weekno,yearno)
on case week_dayno
case 1:
tihra100.endy = tcdynm.sunday
break
case 2:
tihra100.endy = tcdynm.monday
break
case 3:
tihra100.endy = tcdynm.tuesday
break
case 4:
tihra100.endy = tcdynm.wednesday
break
case 5:
tihra100.endy = tcdynm.thursday
break
case 6:
tihra100.endy = tcdynm.friday
break
case 7:
tihra100.endy = tcdynm.saturday
break
default:
tihra100.endy = empty
break
endcase

lvdvelde
8th December 2003, 14:54
Thanks for your input guys. After thinking really deep I can only conclude this:

there is nothing wrong with the function num.to.week().
Because I have monday defined as the first day of the week, it will return weekday "1" for every monday (date) I put into it.

The trouble begins when I want to use this return value for querys on tihra100 or tihra120. What's needed then is something like a reverse conversion according to all the enum values of tcdynm. Which means a simple statement like:

if wday = 7 then
wday = 1
else
wday = wday + 1
endif

Now let's see if this works!

robertvg
17th April 2007, 17:13
ohoh...old subject, same problem.

I experience the same issue here.
Input date: 05-08-2007 (732893), definitely a Sunday.
Num.to.week returns: 7 ! Should be: 1
I have set the first day of week to Sunday for company 000 as well as the company I'm working in.
The information of num.to.week says indeed the calculation is according the data dictionary, but what part of it exactly ?

mark_h
17th April 2007, 18:03
According to the help it is the company data settings. Not sure if that answers your question. I am also not sure what all you need to do to make a new day of week active. Saturday is our first day and it returns 2 with your date.

robertvg
18th April 2007, 17:31
found the solution: in taad1100m000 (maintain companies - where you specify the first day of the week) there is a "convert to runtime", but there is also a "convert to runtime DD..." that actually re-creates the users runtime DD files: in the u* files the first day of the week is also written (depending on the startup company linked to the user).
This solved it.

Regards,