My simple timer is defined as:
let now = Date.now
var start = Calendar.current.date(byAdding: .second, value: Int(16), to: now)!
var end = Calendar.current.date(byAdding: .second, value: Int(16), to: start)!
Text(timerInterval: start...end, countsDown: false)
I was expecting to start counting it like: 00:16
, 00:17
, 00:18
... 00:32
.
But it works like 00:00
, 00:01
... 00:16
and starts counting 16 seconds after load.
How can I start it from given interval and end on a given interval from future?
This should achieve what you'd like. You need to subtract 16 from now so the timer knows to start from 16s in the past. The timer is always relative to now.
let now = Date.now
var start = Calendar.current.date(byAdding: .second, value: Int(-16), to: now)!
var end = Calendar.current.date(byAdding: .second, value: Int(16), to: start)!
Text(timerInterval: start...end, countsDown: false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With