I intend to allow the user to type out a day in a picker (e.g Monday) then have the app get the date for the next Monday in dd:mm:yy as a string which I can then use to insert the data into Gregorian.moment(options).
I intend to allow the user to type out a day in a picker (e.g Monday) then have the app get the date for the next Monday in dd:mm:yy as a string which I can then use to insert the data into Gregorian.moment(options).
I would use weekDay number
desireDay = Today + ( (D-T+7)%7)
where D = desire weekDay number, T = Today weekDay number
So how could I work this into my string from the picker. Like this?:
e.g
d = null;
t = insert current day getting code here
dayGiven = “pickeroutput”
if (dayGiven == “Monday” ) {
d = 1;
}
desireDay = Today + ( (D-T+7)%7);
desireDay now equals e.g “17.03.2023”
P.S (I meant to say that it should be dd:mm:yyyy)
hi,
in the settings, either you ask for the user to put a number from 1 to 7 where Sunday = 1 etc
see here https://developer.garmin.com/connect-iq/api-docs/Toybox/Time/Gregorian.html
or a listBox where Sunday = 1 etc.
I’ve made it so typing in either mon or Monday returns a number and the same for the other days of the week.
Should I guess you don't know at all how to deal with Date and time in monkeyC ?
if yes, let me know and I will write the code in clearer way
In my opinion, it is not a good idea to return only dd:mm.yyyy format, US use mm.dd.yyyy format, Chineses use yyyy.mm.dd format and I can say with my little xp that you have as many date format as users.
as long as it returns the same numbers as Garmin, the formula will work
but don't forget to put a default value if the user makes a mistake in typing, that is why I think it is better to either out a listbox or a formated number box
I agree. Either DD/MM/YYYY or MM/DD/YYYY will be ambiguous. For example, Canada has used DD/MM/YYYY but due to proximity with the US, we often use MM/DD/YYYY. so it's ambiguous when someone writes something like "11/12/2022", depending on the context.
Arguably, YYYY-MM-DD is unambiguous (since nobody uses YYYY-DD-MM), but not everyone may prefer it.
Might be best to allow the user to select a date format.
I haven’t really worked with dates or time much I admit. I’d appreciate something at the end of the code like //“this is the expected result”.
I’ll also figure out letting the users watch settings date format thing.
ok, here is a clearer code:
using Toybox.Time.Gregorian as Date:
using Toybox.Time;
var T=Time.Today(); //(today moment)
var Tdow = Date.info(T,0).day_of_week; //(today day of week = 7, saturday)
var Ddow = 5; // where you put the user desire day number
var NdD = (Ddow - Tdow + 7) % 7; // this wil give number of day between today and next desire day
NdD = NdD * 86400; // now the result in seconds
NdD = T.value() + NdD // the unix timestamp of next desire day
NdD = new Time.Moment(NdD); // gives you a moment objet, from the one you will be able to extract the date.
NdD = Date.info(NdD,0);
System.println(NdD.day+"."+NdD.month+"."+NdD.year);
Wow, I’m grateful you took the time to write it all out, I shall try it out later.