Rama
(Rama)
May 8, 2014, 9:12pm
1
Dear Friends at Epic,
I know that my actual FTime data is sound, because I have an FString version that works correctly using the same exact data.
Trying to use FText, I can get FDate to work correctly.
#What Almost Works: FDate
SaveDate = FText::AsDate(SaveDetails.SaveDate.ToDate());
It almost works! It’s off by one day.
My ToString() version shows the correct day however.
SaveDate = USolusCore::DateToString(SaveDetails.SaveDate);
//Date To String
static FORCEINLINE FString DateToString(const FDateTime& Date)
{
return USolusCore::MonthToString(Date.GetMonth()) + FString(" ") + FString::FromInt(Date.GetDay()) + FString(" ") + FString::FromInt(Date.GetYear());
}
#What Doesnt Work: FTime
FTime does not work correctly, at all
SaveTime = FText::AsTime(SaveDetails.SaveDate.ToTime());
My FString version works wonderfully!
SaveTime = USolusCore::TimeToString(SaveDetails.SaveDate.ToTime());
//Time to String
static FORCEINLINE FString TimeToString(const FDateTime::FTime& Time)
{
return FString::Printf(TEXT("%02i"),Time.Hour) + FString(":") + FString::Printf(TEXT("%02i"),Time.Minute) + FString(":") + FString::Printf(TEXT("%02i"),Time.Second);
}
#Picture
#Question
Why is FTime printing a date at all?
In addition to the date and time being wrong, I dont think it is AsTime’s job to print the whole date
Rama
Rama
(Rama)
May 8, 2014, 9:21pm
2
#Proof that AsDate and AsTime are not working correctly
I just wrapped my string version in FText, and am still printing FText, using this code it looks like this:
SaveDate = FText::FromString(USolusCore::DateToString(SaveDetails.SaveDate));
SaveTime = FText::FromString(USolusCore::TimeToString(SaveDetails.SaveDate.ToTime()));
Rama
(Rama)
May 8, 2014, 9:26pm
3
#Thank You Gerke Preussner!
Thanks for letting me know!
#
Rama
It also seems to not handle DST correctly.
I ran the following when my system time was the 8th May 2014 at 22:23:31 BST (GMT+1 for DST):
FDateTime Now = FDateTime::Now();
FText DateText = FText::AsDate(Now.ToDate()); // 8 May 2014
FText TimeText = FText::AsTime(Now.ToTime()); // 1 Jan 1970 23:23:31 - that's just plain wrong
FText DateTimeText = FText::AsDateTime(Now); // 8 May 2014 23:23:31 - that's an hour out, it's 22:23:31, probably DST
Thanks Rama, we already know about this issue. I actually spent some time last week trying to track it down. It looks like the problem is in the ICU library. I think it might have a bug with leap years or something like that, because older dates (i.e. from 1990) seem to work properly. We will try to fix this soon.
Rama
(Rama)
May 8, 2014, 9:47pm
6
I am glad to have helped bring this to attention!
Thank you for UE4, Jamie and Gerke!
Rama
The issue with FTime coming out as a date is because we’re using the wrong formatter (ICUDateTimeFormat rather than ICUTimeFormat; see FCulture::FICUCultureImplementation::GetTimeFormatter).
I’ll fix that tomorrow… it doesn’t help the date being off though