Unable to set minHour to 00 in flatpicker for maxDate - flatpickr

I am unable to set minHour for the maxDate to 00 hours.
//calendar
var calendar = $("#basicDate").flatpickr({
dateFormat: "Y-m-d H:i",
defaultDate: new Date(),
enableTime: true,
time_24hr: true,
minDate: new Date(),
maxDate: new Date(),
minDateHasTime: true,
maxDateHasTime: true,
hourIncrement: 1
});
var minDateRec = "2020-12-07T00:00";
var maxDateRec = "2020-12-15T00:00";
var minDateRecFom = new Date(minDateRec);
var maxDateRecFom = new Date(maxDateRec);
calendar.set("minDate", minDateRecFom);
calendar.set("maxDate", maxDateRecFom);
If I change maxDateRec to 2020-12-15T01:00 it works(as in the increment does not happen beyond 01 hours, but not for 00 hours - increment happens.
Codepen link below
https://codepen.io/DPK_RAO/pen/qBajMxg

I changed the minute settings to 01, it works
var maxDateRec = "2020-12-15T00:01";

Related

return wday, day, mon. and yr using javascript dateformat in a browser window

var today = new Date();
var dateOptions = {
weekday:"long",
day: "numeric",
month: "long",
year: "numeric"
};
var day = today.toLocaleDateString("en-US", dateOptions);
returns empty window, shows nothing at all
what do u mean?
u can use
var date = new Date().toUTCString()
var hour = new Date().getUTCHours()
var day = new Date().getUTCDate()
var month = new Date().getUTCMonth()
var year = new Date().getUTCFullYear()
var mstime = new Date().getUTCMilliseconds()
console.log(date)
console.log(hour)
console.log(day)
console.log(month)
console.log(year)
console.log(mstime)
//! expected output
Date : Sun, 23 Oct 2022 17:49:20 GMT
Hour : 17
Day : 23
Month : 9
Year : 2022
Get a time but in ms : 1666547360034

NodeMailer - ICALToolkit Event Days are Always Incorrect by -1 Day on Start & -2 Day on end

The Dates on my NodeJS Side are Correct.
Once The User receives the event (On Their Email Client) the dates are Incorrect.
The Dates are always off by an Exact amount
-1 On the Starting Day E.G 02 Feb -> 01 Feb.
-2 On the Ending Date E.G 05Feb -> 03Feb
Dates are Received from an Angular Application, I can confirm the dates provided are correct dates Formatting is another matter.
Is my Formatting Incorrect? & or Is this a TimeZone Problem?
Please find Below Code:
I am Unsure How to Recreate a working Example of a Node.js Application
using the SO builder, Please Lend guidance regarding this if required and I will update were needed
var startDate = new Date(user.sDate)//YYYY/MM/DD;
var EndDate = new Date(user.eDate)//YYYY/MM/DD
var builder = icalToolkit.createIcsFileBuilder();
builder.calname = 'Temp Cal';
builder.timezone = 'Africa/Johannesburg';
builder.tzid = 'Africa/Johannesburg';
builder.method = 'REQUEST';
console.log(startDate + " sDate") //Sat Feb 25 2023 00:00:00 GMT+0200 (South Africa Standard Time)
console.log(user.eDate + " eDate") //2023/02/27 eDate
builder.events.push({
//Required: type Date()
start: startDate,
end: EndDate,
summary: 'Test Event',
allDay: true,
description: 'Testing it!',
organizer: {
name: 'SomePlace ',
email: 'someemail#mail.com',
sentBy: 'someemail#mail.com'
},
method: 'REQUEST',
status: 'CONFIRMED',
})
var icsFileContent = builder.toString();
let mailOptions = {
from: 'emailsending#mail.com', // sender address
to: "whicheveremail#mail.com", // list of receivers
subject: "New Booking Made", // Subject line
html: `<h1>Hi ${user.name}</h1><br>
<h4>Here is your new Booking</h4><br>
<p>Calendar Event Here: </p>
<p>${user.sDate}</p><br>
<p>${user.eDate}</p><br>`,
alternatives: [{
contentType: 'text/calendar; charset="utf-8"; method=REQUEST',
content: icsFileContent.toString()
}]
};
let info = await transporter.sendMail(mailOptions);
callback(info);
Extra info:
Angular App Date Formatting:
const format = 'yyyy/MM/dd';
const startD = sy+ "-" + sm + "-" + sd;
const endD = ey+ "-" + em + "-" + ed;
const locale = 'en-US';
const formattedDateStart = formatDate(startD, format, locale);
const formattedDateEnd = formatDate(endD, format, locale);
this.SendEmail(formattedDateStart,formattedDateEnd);

Why there is a difference in node js Date() object values in console.log()?

I am new to node and I was going through Date() object, values and Date format in Node. When I run the below code, I get different output in console.
const date_1 = new Date();
console.log(date_1);
const date_2 = new Date();
console.log(+date_2);
const date_3 = new Date();
console.log('comma:',date_3);
const date_4 = new Date();
console.log('plus:'+date_4);
gives the below output in console?
2018-02-01T06:55:41.327Z
1517468141327
comma: 2018-02-01T06:55:41.327Z
plus:Thu Feb 01 2018 12:25:41 GMT+0530 (India Standard Time)
Can someone let me know what I am missing here in terms of understanding.
For the first and third case are displayed as default
new Date().toJSON()
For second case +new Date() unary operator, it's equivalent to:
function(){ return Number(new Date); }
For the fourth case 'plus:'+date_4, the string are concatenated as result the date is equivalent to
'plus:'+date_4.toString()
The value of new Date() is the universal format(Z) so when you log a date, It's value is logged.
console.log(date);
console.log('abc',date);
But when + operator with a number of just + is used it converts it to Number format(milliseconds in case of date) -
console.log(+date);
console.log(1+'a'); // NaN
And when you use + with a string, It gets toString() value of date which is Thu Feb 01 2018 12:45:21 GMT+0530 (IST)
console.log(date.toString()); // Thu Feb 01 2018 12:45:21 GMT+0530 (IST)
You are implicitly converting your date to something else:
const date_1 = new Date();
console.log(date_1); //prints date as a Date object
const date_2 = new Date();
console.log(+date_2); //converts date to a number
const date_3 = new Date();
console.log('comma:',date_3); //prints date as a Date object
const date_4 = new Date();
console.log('plus:'+date_4); //converts date to a String

How to save mongoose date-time in particular time-zone

Mongoose is saving date-time as ISODate("2017-04-25T09:40:48.193Z")in UTC format. How can i change its time zone to my local server timezone. So i need not to change the time every time i retrieve it from db. Here is my model schema:
var MyModelSchema = new mongoose.Schema(
{
id: Number,
description: String,
created: {type: Date},
modified: {type: Date, default: Date.now},
},
{
collection: 'my'
}
);
PS: I am aware that it is preferred to save time in UTC format but here my requirement is to save it in specified time-zone.
you can save users timezone and while updating add the time zone value to this new object. Better to use moment.js to convert this.
moment
Even thought it is not a good practice to store time in local format but this might help -
date = new Date(); //2017-04-25T06:23:36.510Z
date.toLocaleTimeString(); //'11:53:36 AM'
localDate = ""+d; //'Tue Apr 25 2017 11:53:36 GMT+0530 (IST)'
changes will be done where you are saving the Object -
var date = new Date(); //2017-04-25T06:23:36.510Z
date.toLocaleTimeString(); //'11:53:36 AM'
var localDate = ""+d; //'Tue Apr 25 2017 11:53:36 GMT+0530 (IST)'
var newModel = new ModelSchema()
newModel.description = 'Something';
newModel.created = locaDate;
newModel.save(function(err) {
if (err)
throw err;
return done(null, newUser);
});
I think I have a solution. Try this one for Asia/Calcutta this can be stored as Date type in Mongoose
function getCurrentIndianDateTime(){
var moment = require('moment-timezone');
var time = moment.tz('Asia/Calcutta').format("YYYY-MM-DDTHH:MM:ss");
return new Date(time);
}

Issues when trying to format DATE from mongodb

I am trying to format a date type property on a model before displaying it. This is the code that I am using:
// MODEL
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var ArticleSchema = new Schema({
title: String,
content: String,
author: { type: String, default: 'Vlad'},
postDate: { type: Date, default: Date.now }
});
ArticleSchema.methods.formatTitle = function() {
var link = this.title.replace(/\s/g, '-');
return '/article/' + link;
};
ArticleSchema.methods.snapshot = function() {
var snapshot = this.content.substring(0, 500);
return snapshot;
};
ArticleSchema.methods.dateString = function() {
var date = new Date(this.postDate);
return date.toDateString();
};
module.exports = mongoose.model('Article', ArticleSchema);
And on the client side I try to display the formatted date using:
{{ article.dateString }}
Still, whenever I load a view that contains this element, I get a 500 error:
Cannot call method 'toDateString' of undefined
EDIT1: I have no issue embedding {{ article.snapshot }} in my Views, but when it comes to the Date object, I get an error
EDIT2: When logging the dateString method using console.log(article.dateString()) I get the following:
Wed Sep 18 2013
EDIT3: This is when I get when using the code provided by dankohn. Is it just me, or is it simply running the method two times in a row?
this.postdate: Wed Sep 18 2013 23:27:02 GMT+0300 (EEST)
parsed: 1379536022000
date: Wed Sep 18 2013 23:27:02 GMT+0300 (EEST)
toString: Wed Sep 18 2013
Wed Sep 18 2013
this.postdate: undefined
parsed: NaN
date: Invalid Date
toString: Invalid Date
I've rewritten this to make perfectly clear where your date stuff is failing:
ArticleSchema.methods.dateString =
console.log('this.PostDate: ' + this.postDate)
var parsed = Date.parse(this.postDate)
console.log('parsed: ' + parsed)
var date = new Date(parsed);
console.log('date: ' + date)
var toString = date.toDateString();
comsole.log('toString: ' + toString)
return toString;
};
Separately, if this doesn't work for you, I recommend the library moment, which is much easier to work with than native Javascript dates.

Resources