Hello people,
I am running a timetabling app using Meteor (offline) that takes in a CSV file as a string that contains Start Times and End Times. The format of the time is HH:MM PM/AM (E.g 11:45 AM / 12:00 PM) that’s start and end times.
I want the app to compare server time, and check if the current time (e.g 11:50 AM) and see if it is smaller than end time and greater than the start time, and show that relevant timeslot’s information.
I managed to make it show relevant information by checking if the current time equal to the start and end times of the timeslot, but that runs every second and makes the app very slow at times, and sometimes it activates two timeslots which cause the wrong slot to show with the right one. I’m sure there is a better way of doing it.
Yes I did that, by converting and parsing to int. I’m just struggling with how to approach the whole comparison bit. I would imagine something close to this pseudo
timetables.find({Timestart: greater than current time}, {TimeEnd: less than current time});
Am I on the right track? What would be the greater or equal / less or equal code in JS? I tried the ‘>=’ and ‘<=’ but they did not work.
@izh93 It depends what you want to achieve exactly (why do you want to compare server time with the start-end interval), the amount of data to be processed, if the timetable changes or not (just one-time csv import and no change until next import?), what is the purpose of isActive field, etc …
It seems that this subscription would do the job
I recommand to use moment package and normalize all time data you put in Collections with moment().toDate(), so all you queries in Mongo will be “native”.
Read this about camelCase, check you code with your editor with eslint
Each slot has a start time and an end time. They are strings put in the CSV.
I want to show relevant time slots when the current time is between their start time and end time.
the isActive is just a way I hacked together very quickly to check if current time equal to start time (String comparison) and if so, set isActive to true, and hence showing the relevant information. It is set to false once the end time equals current time. It wintended inteded, but sometimes it activates the wrong slot and the wrong one stays active until its timeEnd is equal to current time (could be a whole day before that happens).
Hence, I wanted to figure out a way to compare current time and see if it is equal or in between start and end times, and return that particular collection document. I can’t seem to do so as the the CSV has the details in strings (eg 12:00 PM) , and I can’t seem to compare a string with a time (e.g timeStart(string): { $gt: currentServerTime(date) } I’m kind of stuck there.
How can I convert them to moment.js? I have dealt with momentjs before but still struggle with it.
I appreciate the time and effort you guys are investing in helping me.
where TS24 and TE24 are just the times in the 24 format, and Session.get("timeCheck") is just a session that gets the server time as a number in the same format (e.g 1315 is 1:15 PM).
I will test this over a 24-hour cycle and see if it produces any errors or doubling, otherwise, I will mark as solved. Thank you for your help, truly appreciated!