Method `ToShortPersianDateTimeString()` not converting to local time
Closed this issue · 1 comments
ariadarkkkis commented
Summary of the issue
Method ToShortPersianDateTimeString()
doesn't covert DateTime
to local time although I pass true in method parameter.
I'm currently using it in mapping profiles.
Environment
DNTPersianUtils.Core version: 4.3.0
.NET Core SDK version: 5.0.300
IDE: Jetbrains Rider
Example code/Steps to reproduce:
Expected code to work:
CreateMap<ReportDescription, DescriptionSaveDto>()
.ForMember(x => x.DescriptionDatetime, opt => opt.MapFrom(y => y.DescriptionDate.DateTime.ToShortPersianDateTimeString(true)));
Current workaround (manually convert the DateTime to LocalTime using ToLocalTime()
, then call ToShortPersianDateTimeString()
method:
CreateMap<ReportDescription, DescriptionSaveDto>()
.ForMember(x => x.DescriptionDatetime, opt => opt.MapFrom(y => y.DescriptionDate.DateTime.ToLocalTime().ToShortPersianDateTimeString(true)));
Output:
Current behavior:
DescriptionDate
in database: 2021-06-27 05:33:47.826278
DescriptionDatetime
return value in Dto: 1400/04/06 05:33
Expected behavior:
DescriptionDatetime
return value in Dto: 1400/04/06 10:03
VahidN commented
If your dateTime.Kind
is not DateTimeKind.Utc
, it won't be touched and If you are using the EF-Core here, you should use this converter to fix it.