Hi all,
I've got a method which takes some parameters and generates some XML to be sent to an [archaic] web service.
I need to include in the XML:
Date (yyyy-mm-dd)
Opening time (hh:mm)
Closing time (hh:mm)
Now in the past when I've had to provide a date/time separately, I've taken in a single DateTime parameter and formatted the date into one field and the time into another.
In this scenario, I've got a single date and 2 times of day.
My initial approach was 3 input fields - one Date, 2 timespans. This feels wrong as the timespans can cover more than a day.
Another idea was to take 2 dates - use one for the date field and then the times from both for the other fields. This feels wrong as the dates provided may actually be different days.
The last option I can think of is having a OpeningDateTime
parameter and an OpenDuration
timespan, however, since the opening/closing times are stored against day of the week (not date), the developer would need to calculate the timespans themselves - which seems silly as it breaks DRY principles. Not to mention that again the timespan can be > 1 day
In short, I've got 3 solutions which would work but none of which feels right - and the first 2 solutions would only pick up problems at run-time. I'd prefer it if the method definition was such that passing in invalid data was difficult (if not impossible) - This would then be seen at design time
Maybe I'm over-analysing but there must be a neater way to do this
Does anyone have a preferred method and if so, why?