Lorenzo Cutrupi
Lorenzo Cutrupi

Reputation: 720

DateTime.add() doesn't effectively add the requested amount of time

I have these small lines:

Timestamp timestamp = document.get("timestamp");
DateTime time = timestamp.toDate();
time.add(const Duration(hours: 3));
print(time);

And before adding hours this is time: enter image description here

And after adding 3 hours its value is the same: enter image description here

What can it be caused by?

Upvotes: 1

Views: 31

Answers (1)

esentis
esentis

Reputation: 4666

If you check the documentation of the add method you will see that it's not a setter, rather it returns a new DateTime so you need it to assign to a new value.

var threeHoursFromNow = time.add(const Duration(hours:3));

Upvotes: 2

Related Questions