PDA

View Full Version : GlobalDateTimeFunctions



IJmert
21-Feb-2017, 08:13 AM
In addendum to the global date and time functions.

There is a new function that calculates the week number of a given date.
There is no function that returns the first day in a given week. I wrote this function, maybe you can add it to the package.....

Function DateGetFirstDayOfWeek Global Integer iYear Integer iWeek Returns Date
DateTime dtFirstDay
Date dFirstDay
Integer iDay
If (iWeek = 0 or iYear = 0) Function_Return 0
// 4th of Januari is always first week of year
Move (DateSetDay (dtFirstDay,4)) to dtFirstDay
Move (DateSetMonth (dtFirstDay,1)) to dtFirstDay
Move (DateSetYear (dtFirstDay,iYear)) to dtFirstDay
Move (DateGetDayofWeekISO (dtFirstDay)) to iDay // 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday, 7=Sunday
Move (DateAddDay (dtFirstDay, (-1 * iDay + 1))) to dtFirstDay
Move dtFirstDay to dFirstDay
Move (dFirstDay + ((iWeek -1) * 7)) to dFirstDay
Function_Return dFirstDay
End_Function

Dennis Piccioni
21-Mar-2017, 08:48 AM
Hi IJmert,

suggestion logged.

Vincent Oorsprong
21-Mar-2017, 10:54 AM
IJmert,

It looks like you take a static number for the first day of week determination. I think a standard function should query the Windows User Locale for this. To do so add:


Define LOCALE_IFIRSTDAYOFWEEK for |CI$0000100C // first day of week specifier, 0-6, 0=Monday, 6=Sunday
Move (GetLocaleInfo (Locale_User_Default, LOCALE_IFIRSTDAYOFWEEK, AddressOf(iFirstDayOfWeek), SizeOfType(Integer))) to iRetval

Peter van Mil
22-Mar-2017, 05:29 AM
Hi Vincent,

In a lot of cases developers do NOT want to be depended on the value of Windows locale. The week number is calculated based on ISO rules and we want to follow these rules. The new DateTime functions in DF 18.2 are a big improvement and we are happy with it. But there is always room for further improvement.

(Using Windows User Locale an be interesting for other purposes).

Evertjan Dondergoor
22-Mar-2017, 07:06 AM
If you do use ISO-dates, using the UserLocaleInfo makes no sense, but AFAIK there are a whole bunch of countries who did not commit to these ISO rules. In those cases, it might be an option to use the UserLocaleInfo, although that still depends in the situation.

Marco
22-Mar-2017, 07:54 AM
ISO week is as it says standardised. So if this function. Is added (good idea) make sure that it is called isoweek or so. But agree that weeknumbers are not everywhere is the world as focussed on and unambiguous as in Europe.

Peter Crook
27-Mar-2017, 02:18 PM
Well, we all know that the purpose of international stansards is so that the USA can be different:D

Garret Mott
27-Mar-2017, 04:20 PM
No - we're exceptional! ;)

When it comes to measurements, it's us & Myanmar against the world - so we must be right, right?

Marco
28-Mar-2017, 04:31 PM
Hi Garret

But you are part of the New World, and its kind of interesting that the Old World seems better in embracing change...

See ya in ATL

Garret Mott
28-Mar-2017, 04:34 PM
True 'nuf.

Sorry Marco - I won't be making it to Atlanta this year. I'll miss seeing folks.

Peter Crook
6-Apr-2017, 12:55 PM
They haven't had enough time to get used to the old ways yet.