Any feature to get the Week number of a date ?
Jocelyn <[email protected]>
| Newsgroups | gmane.comp.lang.eiffel.gobo.general |
|---|---|
| Message-ID | <[email protected]> |
Hi there,
Using the DT_GREGORIAN_CALENDAR, is there a way to get the week_number
of a date ?
What I managed to do quickly using the Gobo classes is the following :
(I am sure there is an better way to compute this)
week_number (d: DT_DATE): INTEGER is
-- Week number for date `d'.
require
date_not_void: d /= Void
local
nyd: DT_DATE -- new year day
days_to_monday: INTEGER
offset: INTEGER
do
create nyd.make (d.year, d.january, 1)
if not nyd.day_of_week.is_monday then
if nyd.day_of_week.code > nyd.day_of_week.thursday_code then
offset := 0
else
offset := 1
end
days_to_monday := 7 - (nyd.day_of_week.code -
nyd.day_of_week.monday_code)
end
if d.day_count >= nyd.day_count + days_to_monday then
Result := 1 + (( d.day_count - (nyd.day_count +
days_to_monday)) / d.days_in_week).truncated_to_integer + offset
else
Result := offset
end
inspect Result
when 0 then
if nyd.day_of_week.code > nyd.day_of_week.thursday_code then
create nyd.make (d.year - 1, d.december, 31)
Result := week_number (nyd)
else
Result := 1
end
when 53 then
create nyd.make (d.year + 1, d.january, 1)
if nyd.day_of_week.code > nyd.day_of_week.thursday_code then
Result := 53
else
Result := 1
end
else
end
end
To Post a message, send it to: [email protected]
To Unsubscribe, send a blank message to: [email protected]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/gobo-eiffel/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/