javascript - Mongoose 的日期未按预期运行
问题描述
正如标题所说,我已经在这个问题上工作了几天,但仍然无法解决它。基本上我想做的很简单。我正在尝试构建一个不和谐的机器人来获取某事开始的日期和该事件结束的日期。特别是当用户键入“开始”时,我应该在写入时注册,然后注册“结束”命令的时间。
这是start的代码。
if (args == 'start') {
if (!message.member.voice.channel) return message.channel.send(`<@${message.member.id}> you have to join a **voice channel** so we can catch your suspicious attempts lol`);
if (user.studystarted) return message.channel.send(`<@${message.member.id}> Your study has started! whisper: *stop procrastinating*`);
await profileModel.updateOne({
userID: message.author.id,
}, {
$set: {
studystarted: true,
},
$currentDate: {
studystart: true,
}
}, {
upsert: true,
});
这是end的代码;
if (args == 'end') {
if (!user.studystarted) return message.channel.send(`<@${message.member.id}> how are you going to end it if you haven't started?`);
await profileModel.updateOne({
userID: message.author.id,
}, {
$currentDate: {
studyend: true,
}
}, { upsert: true });
let starttime = user.studystart;
let endtime = user.studyend;
console.log("start time: " + starttime);
console.log("end time: " + endtime);
let diffTime = (endtime.getTime() - starttime.getTime()) / 1000;
await profileModel.updateOne({
userID: message.author.id,
}, {
$inc: {
studytotal: diffTime,
weeklytime: diffTime
},
$set: {
studystarted: false,
}
});
我已经尝试了很多方法来设置日期,但我看不到任何一种方法。它几乎总是以结束时间写在前面而开始时间写在后面,这不应该是它的工作方式。
任何建议表示赞赏。我是初学者
解决方案
推荐阅读
- python-3.x - 通过将每个下一个列表与前一个列表进行比较并存储唯一列表来迭代 Python 中的列表列表
- java - ditJava 更改 graphics2D 的 dpi
- python - 是否有用于不可消费的可迭代对象的 python 类型注释?
- javascript - Web Share API - 从服务器共享文件
- xpages - 如何将 CKEditor 的 MIME 转换为与 NotesClient 上的外观相同?
- ios - Swift:禁用夜班(非黑暗模式)
- visual-c++ - MSBuild - MSB4019 由于路径无效 (Visual Studio 2019)
- android - 保存文件时的回调
- javascript - 如何在侧模板标签中调用 vue.js 方法并显示方法返回数据
- javascript - 从 JSP/Ajax 中填充的带有按钮的清除下拉 Select2 只能工作一次