Why can't I add time to my FDateTime variable?

I’m trying to build a very simple in-game clock and calendar by using a FDateTime variable to hold the game world’s date and time. In order to increment the in-game clock correctly, each tick I multiply DeltaTime by the game time/world time ratio; if I want 2 seconds to pass in-game for every second in real-life I multiply the delta by 2, if I want a full minute to pass for each real-life second I multiply it by 60:

float adjustDelta = DeltaTime * gameSecondsPerWorldSecond; //convert real time into game time
dateTime += adjustDelta; //Add the adjusted delta to my FDateTime variable
debugSec = dateTime.GetSecond(); //Drop the HH:MM:SS values to public variables so I can monitor their value in the inspector
debugMin = dateTime.GetMinute();
debugHour = dateTime.GetHour();

This compiles cleanly, but when I run it and view my debug floats in the inspector, all three remain at 0 and never increment. My assumption is that the mistake lies in trying to add a float to an FDateTime, but since the compiler didn’t produce a type mismatch I’m not really sure what I should be changing to properly increment time.

You have to construct a new FDateTime and do

dateTime += NewDate.

And FDateTime members are int32 data, adding adjustDelta won’t do anything.

Hmm okay… how would I manually add seconds/minutes/whatever to NewDate, to ensure I’m not just adding a blank date to my existing one? Playing with intellisense shows me getters for each individual field, but I can’t seem to find setters.

I just wanted to add, apparently you can’t actually add FDateTime like this; the following produces an error, “no operator found which takes a right-hand operand of type FDateTime”:

FDateTime modifyTime(0,0,0,0,0,0,DeltaTime);
dateTime += modifyTime;
1 Like

Okay, so I figured out that I’m supposed to use a timespan instead of adding two DateTimes, but that still doesn’t seem to work with deltatime; the following never advances the seconds, minutes, or hours:

FTimespan modifyTime;
dateTime += modifyTime;

modifyTime = modifyTime.FromSeconds(DeltaTime);