After receiving idToken from Google and verified, I noticed its exp: 1623186214 is always set to 1970 which will always expire itself. For example var when=new Date(1623186214); resulting Mon Jan 19 1970 10:53:06 GMT-0800 (Pacific Standard Time).
How to address it? Thank you in advance.
Okay, the exp is in seconds since midnight 01 January 1970 GMT.
So the correct way to check expiration is
var d=new Date('1970-01-01T00:00:00Z'); // 1970-01-01 GMT
d.setUTCSeconds(1623259934); // the value of 'exp', note use UTC not setSeconds().
Now it's Wed Jun 09 2021 10:32:14 GMT-0700 (Pacific Daylight Time), one hour after log in.
However, some better ways to validate it:
use Google's public endpoint
use Google's client library google-auth-library
Details on Authenticate with a backend server
JWT timestamp in seconds, but Javascript Date requiring milliseconds. But both JWT and Javascript Date constructor use the idea “since the epoch”. So just multiple exp by 1000.
new Date(exp * 1000)

Related
I am building a GraphQL server with Node, Express and Apollo. I use Postgres for my database. I have a table called tasks in my database and a column called dueDate with the type timestamp. I have a GraphQL type in my server that looks like this:
type Task {
id: String!
...
dueDate: String
createdAt: String!
updatedAt: String!
}
As you can see, I've declared dueDate as a String. I have a task record in my database where the due date is 2023-01-30T12:00:00.000Z. When I call my GraphQL query to fetch this task, I get 1675060200000 in localhost and 1675080000000 in my DigitialOcean server. I converted these values to human-readable format in https://www.epochconverter.com/ and got back:
Localhost:
GMT: Monday, 30 January 2023 6:30:00 AM
Your time zone: Monday, 30 January 2023 12:00:00 PM GMT+05:30
DigitalOcean Server:
GMT: Monday, 30 January 2023 12:00:00 PM
Your time zone: Monday, 30 January 2023 5:30:00 PM GMT+05:30
I expect to display Jan 30th, 2023 at 5:30 PM in my web application. Why do my local server and my DigitalOcean server return two different Unix timestamps for the same database value? I am unable to figure out if this is an issue with my database or something to do with my Apollo server configuration. What am I doing wrong? Help appreciated!
Without using momentjs on client-side. I need to properly save the date/time to the db and pull it back, followed by converting it to local.
I noticed the material-ui datepicker took care of this before but now I need to do it myself.
The html input 'datetime-local' doesn't like receiving timezone so I'm not sure how to do the whole flow.
I think I need to get UTC date on the client side like this for the db (?)
2021-10-26T01:14:27.920+00:00
And somehow on turn it into something input 'datetime-local' will accept.
Any help appreciated
You can achive in the folllowing ways
// Create date object from datetime string
var date = new Date('2021-10-26T01:14:27.920+00:00');
// Coverting local datetime back to UTC
console.log(date.toUTCString()); // Output "Tue, 26 Oct 2021 01:14:27 GMT"
// Coverting to local datetime
console.log(date.toString()); // Output "Tue Oct 26 2021 06:44:27 GMT+0530 (India Standard Time)"
// Coverting to local timezone
console.log(date.toLocaleString()); // Output "10/26/2021, 6:44:27 AM"
I am using flatpickr in order to set a date,
onChange: function(selectedDates, dateStr, instance) {
var myDate = selectedDates[0];
First I am tracing selecteDate[0] and gives me a string
Thu Dec 20 2018 00:00:00 GMT-0500 (GMT-05:00)
Then I am tracing myDate and seems that is been converted to GMT+0000 ISO string.
2018-12-20T05:00:00.000Z
So my question is where does the flatpickr picks the GMT-0500 from?
Is it possible to change it?
Unfortunately, it doesn't seem to be possible to do that (currently).
https://github.com/flatpickr/flatpickr/issues/1532
Apparently, flatpickr uses, by default, the timezone of the computer.
I'm trying to store a persistent cookie with SimpleCookie, so that I'm doing something like:
def add_cookie(self, name, value, expiry = None):
self.cookies[name] = value
if expiry is not None:
self.cookies[name]['expires'] = expiry
print(self.cookies[name].OutputString())
Output of print:
remember_me=blabla; expires=Sun, 02 Jul 2017 13:30:57 GMT
Of course then it's passed to wsgiref.simple_server's start_response function, with something like
(Set-Cookie, cookie['remember_me'].OutputString())
and the cookie is created on browser/client side, however expiry time is not updating.
Any idea how to set the correct expiry time and make persistent cookie instead of session cookie?
Thanks.
Issue solved, the described method is fine, I was just rewriting the expiry next time automatically, and that's why expiry disappeared always.
My users could create some objects that have specific time and search them by query for specific startTime and endTime.
My question is how should I store these objects in my database (MongoDB)? Should I store them in UTC or with specific timezone that relates to user that create object?
Use UTC date format, and convert all data to UTC: when create, update, delete objects or filter them. Use one UTC time zone helps you avoid a lot of problems, and simplify you code.
example
> var now = new Date();
> Mon May 26 2014 10:55:34 GMT+0300 (Kaliningrad Standard Time)
> now.toUTCString();
> Mon, 26 May 2014 07:55:34 GMT
> new Date(now.toUTCString())
> Mon May 26 2014 10:55:34 GMT+0300 (Kaliningrad Standard Time)
When you create a new Javascript date object and assign it to a Mongo date field, it will automatically be usable with any timezone. If all you need is the current time, you can just use new Date(). But if you need to take a string and have it be interpreted in a specific timezone, or you are going to be presenting a time to a user in a specific timezone, I highly recommend checking out Moment Timezone.
This code will take a date object stored in a Mongo model (which could be 1AM on January 1, 2014 in Sydney, Australia) and present it formatted to a Los Angeles timezone (which would still be December 31, 2013).
collection.find({_id: 123}, function(err, model) {
userDate = moment(model.date).tz("America/Los_Angeles").format("MM/DD/YYYY");
});
And if you ever need to parse a string that doesn't specify a UTC offset as a specific timezone, you can use the constructor:
moment.tz("2013-11-18 11:55", "America/Toronto")