Date format for sitemap - javascript

I'm using gadicohen:sitemaps with Meteor to create my sitemaps and I'm not sure how to set the lastmod date field. The documents state not to use new Date(), so what date format should I use.
{ page: '/x', lastmod: new Date() },

They aren't saying not to use Date as a type, they are saying that you should not create a new Date() every time the sitemap is requested.
Instead, keep in your collection the time that the page was last modified, and use that in the sitemap

Related

How to update Firestore Timestamp to a future value

We have a check-in and check-out component in our web app that simply uses firebase timestamps. However, we need the ability to edit those timestamps in the event someone makes a mistake.
checkInTimeStamp: fb.firestore.FieldValue.serverTimestamp("17:00") simply returns the current time.
Instead of 17:00, what object do we need to pass through the function to get the correct timestamp?
The serverTimestamp() generates current timestamp on server side. You can use a Date object instead to store a future date:
const futureDate = new Date();
// update date to future time
futureDate.setDate(futureDate.getDate() + 5);
db.document('col/doc').set({ checkInTimeStamp: futureDate })
Checkout other method like setDate() in MDN docs.

MongoDB Stored my date with the wrong time

I recently tried to assign a new date in MongoDB, but I have a problem with that, it stored the date I give but it's not correct
userSchema.methods.createPasswordResetToken = async function () {
this.passwordResetToken = crypto.randomBytes(20).toString('hex')
this.passwordResetExpires = moment().format(this.createAt)
await this.save()
console.log(moment().format(this.createAt)) // 2021-12-21T19:01:54+02:00
console.log(this.passwordResetExpires) // 2021-12-21T17:01:54.000Z
return { token: this.passwordResetToken, userId: this._id }
}
mongoDb remove 2 hours when storing it
and when I try to catch the type of two values
I got
console.log(moment().format(this.createAt)) // string
console.log(this.passwordResetExpires) // object
:
user Schema
...
passwordResetToken: String,
passwordResetExpires: Date
...
From the docs:
MongoDB stores times in UTC by default, and will convert any local time representations into this form. Applications that must operate or report on some unmodified local time value may store the time zone alongside the UTC timestamp, and compute the original local time in their application logic.
It seems your server just sits in GMT timezone ( utc +2, you could also see it from your date value // 2021-12-21T19:01:54+02:00 ). I would usually offer some hacky way to get around the issue but this is actually a best practice. Hence I recommend you do your date calculations in UTC and not in machine time.
note your other date is in UTC (2021-12-21T17:01:54.000Z), make sure your comparing apples to apples.

get date from firebase format change

earlier we push date use native Firebase format
createAt:admin.firestore.Timestamp.fromDate(new Date)
so data store like this
"createAt": {
"_seconds": 1563181560,
"_nanoseconds": 567000000
}
new we change like this
createAt:new Date().toISOString()
now store like this
"createAt": "2019-07-17T07:17:05.115Z"
buts some date store like this because we use native date format
now how can i call old date to new date format? moste of the data sote like native date method is that any way to change new method?
The Firestore Timestamp type has many conversion methods. Just like it has a fromDate() it also has a toDate() method. So if you reload the data from Firestore and get a Timestamp object, you can then get a date with timestamp.toDate() and thus an ISO-8859 formatted string with timestamp.toDate().toISOString().

Create timezone-aware date in javascript

When I create objects in my MongoDB using Mongoose, the dates are formatted as, for instance, 2016-10-10T15:35:52.764Z (it might be yyyy-MM-ddTHH:mm:ssZ). If I use Date.now() in JavaScript, I get a timestamp.
How can I create the same date format as Mongoose with javascript?
Edit
It seems I can use
new Date().toISOString();
but what is the difference of, for instance, Date.now() and new Date()?
Are there any reasons for not using new Date() instead of a function under the Date object (that somehow already seems to be initialized without writing new Date()?)
you can use moment.js and run like this
moment().format('YYYY-MM-DDTHH:mm:ss'); // print 2016-10-11T15:25:36

OData Date Filtering from JS

I am using the DXTREME framework from Devexpress to connect a HTML mobile app to an OData source.
One of my tables in SQL Server, exposed through the OData service is a table with a date (not datetime) field in it. It is exposed through OData like this:
<d:TaskDate m:type="Edm.DateTime">2010-04-01T00:00:00</d:TaskDate>
I am trying to filter the data on this field through a calendar control, but when I try to filter the datasource on the JS side, I get no matches. This is because the date is passed to the OData service, I believe, in UTC format, so if I query for TaskDate = '10/JUL/2013', I believe the date is passed as "09/JUL/2013 14:00". If I filter on TaskDate > '10/JUL/2013' I get results back from after "09/JUL/2013 14:00" at any rate.
I have tried declaring a new date with no time part:
filterDate = new Date(2013, 6, 10)
but is still doesn't work, it still subtracts 10 formy time zone on the JS side.
What I want to do is to return a lists of Tasks valid on that particular date. How can I achieve this?
I think my problem was the confusion around the dxDateBox control returning just a date, and that date being changed when passed to my odata service.
I solved the issue by converting the date to UTC myself, but just using the Date parts from the control, (where filterDate came from the control):
var paramDate = new Date(Date.UTC(this.filterDate().getFullYear(), this.filterDate().getMonth(), this.filterDate().getDate()));
this.dataSource.filter(["TaskDate", "=", paramDate]);
This works nicely, but seems rather verbose.

Categories

Resources