D Paste by TSalm
Description: DFLCalendar - module TimeTools
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | module tools.TimeTools; private import tango.time.chrono.Calendar, tango.text.locale.Core; debug { import tango.io.Stdout; } alias Calendar.DayOfWeek DayOfWeek; /*** * Convert the DayOfWeek to his position in the week (0..6) * * Params: * dateTimeFormat = * dow = * Returns: */ uint getPosDayOfWeek(DateTimeFormat dateTimeFormat, DayOfWeek dow) { uint firstDowNum = cast(uint) dateTimeFormat.firstDayOfWeek(); uint dowInt = cast(uint) dow; if(firstDowNum < dowInt) return dowInt - firstDowNum; else return dowInt - firstDowNum + 7; } /*** * Convert the position of a day in a week (0..6) to the DayOfWeek * * Params: * dateTimeFormat = * numDow = * Returns: */ DayOfWeek convertPosDayOfWeek(DateTimeFormat dateTimeFormat, uint numDow) in { assert(numDow < 8); } body { uint firstDowNum = cast(uint) dateTimeFormat.firstDayOfWeek(); uint cvt = numDow + firstDowNum; if(cvt > 6) return cast(DayOfWeek) (cvt - 7); else return cast(DayOfWeek) cvt; } |
(some replies deleted)