Forum Navigation
convert DayOfWeek to numDayOfWeek tango.text.locale.Core.DateTimeFormat
Forum Index
»
Tango Wish List
»
convert DayOfWeek to numDayOfWeek tango.text.locale.Core.DateTimeFormat
Moderators:
kris
Posted: 11/29/08 19:16:42Hello,
I've wrote 2 function to convert the DayOfWeek? to his position in the week (depending on the first day of week) and the contrary.
Does the tango team is interesting ?
Index: text/locale/Core.d =================================================================== --- text/locale/Core.d (revision 4135) +++ text/locale/Core.d (working copy) @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* copyright: Copyright (c) 2005 John Chapman. All rights reserved @@ -1649,6 +1649,48 @@ } /** + * $(ANCHOR DateTimeFormat_getPosDayOfWeek) + * Convert the DayOfWeek to his position in the week (0..6) + * Params: dow = A DayOfWeek value + * Returns: the position in the week (0..6) depending on the first day of the week + */ + uint getPosDayOfWeek(Calendar.DayOfWeek dow) { + + uint firstDowNum = cast(uint) firstDayOfWeek(); + + uint dowInt = cast(uint) dow; + + if(firstDowNum < dowInt) + return dowInt - firstDowNum; + else + return dowInt - firstDowNum + 7; + + } + + /** + * $(ANCHOR DateTimeFormat_convertPosDayOfWeek) + * Convert the position of a day in a week (0..6) to the DayOfWeek + * Params: numDow = the position of the day in the week (0..6) depending on the first day of the week + * Returns: the corresponding DayOfWeek + */ + Calendar.DayOfWeek convertPosDayOfWeek(uint numDow) + in { + assert(numDow < 8); + } + body { + + uint firstDowNum = cast(uint) firstDayOfWeek(); + + uint cvt = numDow + firstDowNum; + + if(cvt > 6) + return cast(Calendar.DayOfWeek) (cvt - 7); + else + return cast(Calendar.DayOfWeek) cvt; + } + + + /** * $(ANCHOR DateTimeFormat_getAbbreviatedMonthName) * Retrieves the abbreviated name of the specified month based on the culture of the instance. * Params: month = An integer between 1 and 13 indicating the name of the _month to return.












