Closed sajjadsaharkhan closed 2 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
@dotnet/area-system-globalization
@ericstj @dotnet/area-system-globalization
It's not there because this:
namespace System.Globalization; public class PersianCalendar : Calendar { public DateTime ToDateTime(DateTime dateTime) { return ToDateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond); } }
isn't correct and doesn't work. You can't encode calendars other than ISO/Gregorian into DateTime
- for instance, DateTime
will prevent day-of-month being higher than 29 for month 2 (and often it being 29 as well).
The anticipated usage pattern for the calendars is that you get the raw numeric values from whatever input source and immediately convert it to DateTime
, then keep it there with the various PersianCalendar.AddXXX
methods.
DateTime.Now
is essentially "already" a Persian calendar date, because that's the anticipated unit of storage/transmission; it's during display/manipulation you need to use the calendars.
Tagging subscribers to this area: @dotnet/area-system-runtime See info in area-owners.md if you want to be subscribed.
Author: | sajjadsaharkhan |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Runtime`, `untriaged` |
Milestone: | - |
It's not there because this:
namespace System.Globalization; public class PersianCalendar : Calendar { public DateTime ToDateTime(DateTime dateTime) { return ToDateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond); } }
isn't correct and doesn't work. You can't encode calendars other than ISO/Gregorian into
DateTime
- for instance,DateTime
will prevent day-of-month being higher than 29 for month 2 (and often it being 29 as well).The anticipated usage pattern for the calendars is that you get the raw numeric values from whatever input source and immediately convert it to
DateTime
, then keep it there with the variousPersianCalendar.AddXXX
methods.
DateTime.Now
is essentially "already" a Persian calendar date, because that's the anticipated unit of storage/transmission; it's during display/manipulation you need to use the calendars.
it's true and I got it thanks
Background and motivation
hi. I'm using
System.Globalization.PersianCalendar
class in my code to convert Utc or system time zone date time to Persian date time. its have a method and gets a date-time from year , month ,day,... It pollutes my code.i think
PersianCalendar
need a new overload forToDateTime
apiAPI Proposal
API Usage
Alternative Designs
No response
Risks
No response