fzupan
September 10, 2019, 4:08pm
1
Hey community,
I have two timepicker items, connected to a collection TIME field on my site, and I wonder if and how I can do some calculations with that?
I want to achive: timepicker2.value (-) timepicker1.value
timepicker2.value = timepicker1.value (+) 30 min
One of my ideas was to extract numbers and return a string but I can’t set the timepicker2 with that string! Please Help!!!
export async function EndZeit(Anfangszeit) {
let Endzeit
let HourValue1 = await Number(Anfangszeit.substr(0, 2));
let MinuteValue1 = await Number(Anfangszeit.substr(3, 2));
if (MinuteValue1 === 30) {
return Endzeit = HourValue1 + 1 +“:00”
} else {
return Endzeit = HourValue1 + “:” + “30”
}
}
Anfangszeit: 09:00:00.000
Endzeit: 9:30
J.D
September 10, 2019, 4:35pm
2
I couldn’t understand what exactly you wish to achieve (maybe try to add clearer explanation),
Anyway 2 comments:
To get the hours and minutes you can use:
let timeSplitter = timeValue.split(":");
let hours = Number(timeSplitter[0]);
let minuets = Number(timeSplitter[1]);
Also you don’t need an async function and await here, as Number() is not a promise.
fzupan
September 10, 2019, 5:48pm
3
Thanks J.D. for your quick feedback.
Maybe my thinking is to complicated!
What is the easiest way to add 15 min to $w(‘#timePicker1 ’).value and display it to $w(‘#timePicker2 ’).value?
J.D
September 10, 2019, 6:06pm
4
Maybe something like this (I didn’t test it):
let timeSplitter = $w("#timePicker1").value.split(":");
let hour = Number(timeSplitter[0]) ;
let sumMinutes = Number(timeSplitter[1]) + 15;
let additionaHours = Math.floor(sumMinutes/60);
let newHour = ((additionaHours + hour) % 24).toString();
let newMinutes = (sumMinutes % 60).toString();
$w("#timePicker2").value = newHour.padStart(2,'0')+ ":" + newMinutes.padStart(2,'0');
(UPDATED (forgot Math.floor())
J.D
September 10, 2019, 6:11pm
5
Updated this line to support date change:
let newHour = ((additionaHours + hour) % 24).toString();
fzupan
September 10, 2019, 6:22pm
6
Oh this is just awesome working! Thanks a lot J.D. you realy saved my day!!!