I am building a reminder bot with Discord.js, and I'm trying to determine whether a user's time input matches local input.
Here are the snippets of my code
Machine Time
const checkTime = () => {
machineTime = new Date() - 0;
console.log(machineTime);
if (inputDate <= machineTime && inputDate != null && machineTime != null) {
console.log("Match found");
}
};
setInterval(checkTime, 1000);
User Input
inputDate = new Date(content[1].replace('-', ' ')) - 0;
Currently, I have a setInterval loop running and creating a new date/time (current time). I then have my code read for user input, ex: "02/2/2023-07:41:30 PM". The input is added to an array, where I pull the time index. I convert both times into timestamps, and use an if statement to determine whether those times match.
However, I'm assuming my user input time is incorrect, as it currently doesnt consider the AM/PM addition. When I try to add in the AM/PM to timestamp conversion, I get an error. Does anyone have an idea of how I can better compare times / fix my issue? Thanks
i want to set end date depend on the balance and start date when the user select the start date,
for example if the start date is 2021-09-01 the balance is 11 so direct the end date will be 2021-09-12
i'm using DatePicer from ant Design ,
this is my code
useEffect(() => {
if (
(selectedLeaveId && selectedLeaveId === LeavesId.annualLeaveId)
) {
const start = startDate;
// this will change the start date too , i dont want that
const directEndDate = start?.add(remainingBalance, 'days');
setEndDate(directEndDate);
}
}, [selectedLeaveId, startDate, remainingBalance]);```
Strongly recommend using moment.js
https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/01-add/
You can pass date as below
let start = moment(startDate)
let end = start.add(DIFFERENCE, 'days');
The problem you are having is because you are modifying the start date object and assigning it to end. I'm not up-to-date on the specifics of moment js but I'd imagine you can do something like:
let end = moment(start).add(DIFFERENCE, 'days');
That way you'll create a new date object for end and add to that one, rather than modifying start.
As a side note, if you aren't going to change what's in the start or end variables you'd be better off writing const start ... rather than let start ... (it will prevent certain bugs from creeping in). This won't prevent you from changing the objects through their methods, it just stops you from accidentally reassigning them.
I am using Node.js V12 with the the trello-node-api package installed. I am able to find all the cards in a list but when I was looking through the json API for the card Link Here I am not able to find the correct title to check to see if the card is over due. I can find if the date was completed but not when the date turns red (Which is what I want) . I am very new with Javascript and I am not sure how to check for the red due date.
Pretty much to sum it up: I dont know how to check to see if a card is over due or not.
Here is the code that I came up with so far
Const trelloNode = require("trello-node-api")("privateinfo")
trelloNode.board.searchCards(boardID).then(function(response) {
response.forEach(element => {
if (element.idList === myListId2) {
var cardLink = element.shortLink;
if () {
//if the card shows the "red due date"
}
}
})
})
```
So I basiclly awnsered my own question.
What I did is added two if statements.
The first one is checking to see if the card even has a due date. The second one is checking the current time against the due date. As I am new to javascript, this may not be the best way but this is my way.
var date1 = element.due;
var date4 = new Date("1970-01-01T00:00:00.000Z") // Reason is because cards that have no due date go back to this date so I have to exclude it.
var date2 = new Date(date1);
var date3 = new Date();
if (date2.getTime() != date4.getTime()){ // Checking to see if a card has a due date
if (date2.getTime() <= date3.getTime()){ // Checking for over due's
I am developping an embedded website contained within a windows CE device.
See it as if it was the web configuration interface of your router.
Everything is contained within a really small footprint of memory, the entire website is less than 500KB with every script, html, css and icons.
We have to assume that the user that is going to 'browse' into that interface does not have access to the internet (LAN only) so no 'online' solution here.
I am looking for a solution so the user choose his timezone and the code will get all the DST/STD times and dates for the next 10-20 years at least and downloaded them to the device that will run autonomously after that and at specific dates, will change its time to DST/STD by itself. Current application is custom (not windowce api related) and needs the DST/STD date pairs.
iana.org is maintaining a db for like every location in the world. I also saw that moment-timezone (javascript interface) is 'packaging' this data in a very compact package 25kb zipped.
I need to know if it is possible to:
'Extract' a main tz list from this DB so the user can choose its own tz. I looked at their doc but example didn't work:
var itsTimeZones = moment.tz.names();
2- Extract the next 10-20 years of DST/STD dates/times for a chosen zone ? I haven't saw any documentation anywhere on this topic. But since it's kind of the purpose of such a database, i would say it must be burried in there somewhere, need a way to dig it out.
3- If moment timezone is not the right track to go, anybody has a solution that will fullfill that requirement ?
Thanxs
My solution for extracting DST list for a given zone from moment-timezone.
1. "theTz" is a numerical index from a change on a select in the webpage.
2. select is populated with "List".
var itsTz =
{
"List" : moment.tz.names(), // Get all zone 'Names'
"Transitions" : [],
};
function TimeZoneChanged(theTz)
{
var myZone = moment.tz.zone(itsTz.List[theTz]); // Get zone by its name from List
var myTime = moment.tz(moment(), myZone.name); // Start today
var myResult;
// Build transition list according to new zone selected
itsTz.Transitions = [];
do
{
myResult = GetNextTransition(myZone, myTime);
if(myResult != null)
{
itsTz.Transitions.push(moment(myResult).format("YYYY/MM/DD"));
myTime = moment.tz(myResult, myZone.name); // Get next from date found
}
}while(myResult != null);
}
function GetNextTransition(theZone, theTime)
{
var myResult;
for(var i = 0; i < theZone.untils.length; i++)
{
if(theZone.untils[i] > theTime)
{
theZone.untils[i] == Infinity ? myResult = null : myResult = new moment(theZone.untils[i]).format();
return myResult;
}
}
}
Results for 'America/Toronto:
2017/03/12,
2017/11/05,
2018/03/11,
2018/11/04,
2019/03/10,
2019/11/03,
2020/03/08,
2020/11/01,
2021/03/14,
2021/11/07,
2022/03/13,
2022/11/06,
2023/03/12,
2023/11/05,
2024/03/10,
2024/11/03,
2025/03/09,
2025/11/02,
2026/03/08,
2026/11/01,
2027/03/14,
2027/11/07,
2028/03/12,
2028/11/05,
2029/03/11,
2029/11/04,
2030/03/10,
2030/11/03,
2031/03/09,
2031/11/02,
2032/03/14,
2032/11/07,
2033/03/13,
2033/11/06,
2034/03/12,
2034/11/05,
2035/03/11,
2035/11/04,
2036/03/09,
2036/11/02,
2037/03/08,
2037/11/01,
I have googled a bit and could not find an answer. So here is my situation.
I have an input of type dateTime. I want to compare the value picked (mobile app for blackberry) to the current date and time. if the selected date is in the future (bigger than date now) I have to show a simple error message. This is all done when the user tries to save the data.
I have tried code like this, but was unsucessfull.
var dateOfIncident = $('#AccidentDetailsDate').val();
var dateNow = Date.now();
if(dateNow > dateOfIncident)
{
// do my stuffs :)
}
This does not work... It passes that validation. I am very new to javascript myself. Any help would be greatly appreciated. I googled and could not find a solution that does not use anything fancy. I need to do it in javascript.
Thanks in advance.
Try this:
var dateOfIncident = new Date($('#AccidentDetailsDate').val()); // or Date.parse(...)
var dateNow = new Date(); // or Date.now()
if(dateNow > dateOfIncident)
{
// do your stuffs...
}
However, if this works may depend on what format your date-string is! You may want to consider this post as well.