calculating sun(first)day of the week

Questions, tips and tricks and techniques for scripting in Servoy

calculating sun(first)day of the week

Postby Harjo » Thu Jun 19, 2003 12:19 pm

I want to calculate by a method the first day of the week (Sunday)

For example if today is 19-06-2003 I want the result back: 15-06-2003(past sunday)

In Filemaker you can do this by setting a field:

Status(CurrentDate) - (DayofWeek(Status(CurrentDate)) -1)


Anyone can help me with this?
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

monday

Postby Bert » Thu Jun 19, 2003 2:42 pm

Always tought monday was the first day of the week :wink:
That's why I'm glad in Servoy monday is the first of the week by default unlike Filemaker where sunday is the first day of the week by default and alway's have (had) to make a workaround with the calculation you mentioned.
Bert de Graaff
ATB Software Servoy Developer manage your business anywhere
User avatar
Bert
 
Posts: 201
Joined: Tue May 20, 2003 11:16 am
Location: Stramproy - NL

Postby Harjo » Thu Jun 19, 2003 3:57 pm

It depends! In bible-terms (christian), sunday is the first the day of the week. In other database and program's monday is the first day of the week!

Does anyone know the method?
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Postby automazione » Thu Jun 19, 2003 5:52 pm

I tried with this method and seems to work:

var a = yourdate;
a.setDate(a.getDate() - a.getDay());


in a you obtain the desidred sunday.
getday() gives you 0 on sunday... 6 on saturday


hope this helps
Enrico Arata
Servoy Italia
automazione
 
Posts: 366
Joined: Thu Apr 24, 2003 11:37 am
Location: Torino, Italy

Postby jcompagner » Thu Jun 19, 2003 9:24 pm

What the first day of the week is depends on youre locale setting (see preferences and then locale tab)
If yours are dutch/NL then Monday is first day of week, if however it is set to USA then Sunday is first day of week.

If you want to know what the first day is in your scripts you can check with the util.isMondayFirstDayOfWeek() (1.1 release)

With that value (true/false) you can write your scripts.

(Don't make scripts that just thinks it starts on sunday or monday!
Because those scripts are made to fail!) ;-)
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby Ron » Sun Jun 22, 2003 10:34 pm

Hi date-specialists...

Q1: I want to get the full year of a date in field1
field1: date_input
field2: date_calc [calculation / stored / INT]:

var a=date_input;
a.setYear(a.getYear())
return a;

Q2: The full year of today (in FMP: Year(Today))
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Postby maarten » Mon Jun 23, 2003 10:50 pm

Q1: I want to get the full year of a date in field1
field1: date_input
field2: date_calc [calculation / stored / INT]:

date_calc > return date_input.getFullYear()


Q2: The full year of today (in FMP: Year(Today))


var today = new Date()
return today.getFullYear()

OR

return new Date().getFullYear()

(new Date() creates a date object with current timestamp)
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby Ron » Mon Jun 23, 2003 10:58 pm

Thanks Maarten.

Ronald
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Postby Harjo » Tue Jun 24, 2003 12:15 am

jcompagner wrote:
What the first day of the week is depends on youre locale setting (see preferences and then locale tab)
If yours are dutch/NL then Monday is first day of week, if however it is set to USA then Sunday is first day of week.


what automazione suggests isnM-4t right then. My local/settings are Dutch=NL The calculation returns still Sunday.

What is the right calculation to get the first day of the week? (dependly what my localsetting are?)
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Postby automazione » Tue Jun 24, 2003 11:02 pm

Hi,

javascript .getday() returns 0 for sunday, 1 for monday.. 6 for saturday.

So if you want the sunday before your date

var a = yourdate;
a.setDate(a.getDate() - a.getDay());

should work and if you want monday ....

a.setDate(a.getDate() - a.getDay() + 1);

and this is independent of the "locale settings"
but if you want the calculated date to depend on your "locale setting" you can test

if (util.isMondayFirstDayOfWeek())
{
a.setDate(a.getDate() - a.getDay() + 1);
}
else
{
a.setDate(a.getDate() - a.getDay());
}

hope this helps (and also hope it's correct), bye

Enrico
Enrico Arata
Servoy Italia
automazione
 
Posts: 366
Joined: Thu Apr 24, 2003 11:37 am
Location: Torino, Italy

Postby jcompagner » Sun Jul 13, 2003 2:02 pm

HJK:

Where do you set youre default locale? Do you mean in windows or mac?

In servoy you can also set youre locale in the preferences->locale tab.

If i have here Dutch then this script:
application.output(utils.isMondayFirstDayOfWeek())

outputs true

if i change it to englisch/usa then it returns false

i test this against RC4
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby automazione » Sun Jul 13, 2003 11:46 pm

in Servoy preferences->locale

1.1 rc4 w2k
Enrico Arata
Servoy Italia
automazione
 
Posts: 366
Joined: Thu Apr 24, 2003 11:37 am
Location: Torino, Italy


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests

cron