|
From: Per W. <pw...@ia...> - 2002-11-10 00:20:04
|
This is a bit naive, since it doesn't take into account that a week
changes at different times depending on locale (sunday or monday being
first day of week), but I don't have the WIN32 help files available right
now - and now win32 compiler either... :-)
bool is_same_week(SYSTEMTIME& s1,SYSTEMTIME& s2) {
FILETIME f1,f2;
ULARGE_INTEGER u1,u2;
#ifndef ALLOW_S2_LESS_THAN_S1
if (s2.wDayofWeek < s1.wDayOfWeek)
/* Given the assumption that s2 must be larger than s1,
* they can't be in same week unless s2 has weekday
* >= s1.
*/
return false;
#endif // ALLOW_S2_LESS_THAN_S1
/* Convert from SYSTEMTIME to a single numeric value */
SystemTimeToFileTime(&s1,&f1);
SystemTimeToFileTime(&s2,&f2);
u1.LowPart = f1.dwLowDateTime;
u1.HighPart = f1.dwHighDateTime;
u2.LowPart = f2.dwLowDateTime;
u2.HighPart = f2.dwHighDateTime;
/* Now have time in 100-nanosecond steps */
#ifdef ALLOW_S2_LESS_THAN_S1
/* if s1 <= s2 isn't a requirement then remove first if case and
* insert this instead
*/
if (u1.QuadPart < u2.QuadPart) {
if (s2.wDayOfWeek < s1.wDayOfWeek) return false;
} else {
if (s1.wDayOfWeek < s2.wDayOfWeek) return false;
tmp = u1.QuadPart;
u1.QuadPart = u2.QuadPart;
u2.QuadPart = tmp;
}
#endif // ALLOW_S2_LESS_THAN_S1
if (u2.QuadPart < u1.QuadPart)
/* End of time interval before start... */
return false;
if (u2.QuadPart > u1.QuadPart > 7*24*3600*(ULONGLONG)(10000000))
/* s2 is more than 7 days away, so can't be in same week. */
return false;
return true;
}
/Per W
On Sat, 9 Nov 2002, Zodiaq wrote:
> Hello Dev-cpp-users,
>
> yeah, I know this is an off topic question - it is not directly
> related to development od Dev-C++ but I also know that this mailing
> list reads quite few people so - do you know a good way to check if
> two dates are inside one week... dates are in SYSTEMTIME or FILETIME
> format... my present idea is not as good as I wish it to be - I start
> from first date and try to get to the second one - if I pass sutarday
> and still not in second I know that weeks are different... but this
> forces some comparisons... know I think that I might check in which
> week of the year both dates are - but how to do that? So - if you have
> any brilliant ideas share them with me!
>
> --
> regards, Zodiaq
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|