0

I want to represent dates with associated zones, but I didn't found any type to represent the date in Noda time (something similar to the LocalDate, but with zone information, so it would by nice to have a ZonedDate structure). How can I store date for specific ZonedDateTime?

For example: I have a structure of type ZonedDateTime = 2015/11/11 1:30 AM and I want to store a date part (2015/11/11) of this time with TimeZone from ZonedDateTime.

Dominik Palo
  • 2,873
  • 4
  • 29
  • 52
  • Perhaps you could elaborate as to *why* you want to represent the data in this way? It's an odd request - there may be an alternative approach, and if not I'd like to better understand the use case. Thanks. – Matt Johnson-Pint Nov 15 '15 at 19:17
  • @MattJohnson I have a collection of items, every item has a property "start time" and I need to create a ComboBox with days containing only days with at least one item (to filter items by starting day by comparing the items start time date part with selected day date part). But all my items uses specific timezone (not system local nor UTC) so I need to show start times of items and combobox items to user in this specific timezone, not recalculated to system timezone or UTC (standard WPF binding with string format). – Dominik Palo Nov 16 '15 at 19:07
  • 1
    Sorry, but I don't quite follow. How does that require a `LocalDate` and `DateTimeZone` bound together into a single object? – Matt Johnson-Pint Nov 16 '15 at 19:31
  • Indeed - it's not clear where the local time zone comes in at all. It sounds like you only need a `List`... – Jon Skeet Nov 16 '15 at 19:42
  • Because if I bind an object without the TimeZone information (e.g. standard c# DateTime), WPF controls displays time to the user recalculated to the system local timezone (but ZonedDateTime are displayed correctly with assigned timezone). So, If I have an item with start time set to 2015/11/16 02:00 AM and assigned timezone UTC+6 and I bind a LocalDate (which is represented by standard C# DateTime) of this item to the WPF control on Windows with local system timezone set to UTC+1, it shows date "2015/11/15" to the user if app is running for example at 01:00 AM of local time zone. – Dominik Palo Nov 16 '15 at 19:46
  • It sounds like this is a problem with the bindings rather than anything else then. Perhaps look into how you could handle all of this without using DateTime at all? – Jon Skeet Nov 25 '15 at 14:10

1 Answers1

2

I suggest you build your own class or struct that just has the pair of them - or use Tuple<LocalDate, DateTimeZone>. There's nothing specific for this in Noda Time at the moment, and I don't expect to add it unless we hear this as a feature request more widely.

Another alternative would be to just use ZonedDateTime and extract the date from it when you need to, probably normalizing to "start of day" (e.g. via DateTimeZone.AtStartOfDay(LocalDate)) for the sake of equality tests. But I'd personally shy away from that as it implies that there is a time-of-day usefully stored there, which in your case there isn't.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194