squeeks / glossy

syslog parser and producer
https://npmjs.org/package/glossy
MIT License
96 stars 29 forks source link

GlossyParser.prototype.parseBsdTime uses getUTCFullYear, yet creates the date in local time #15

Open moll opened 10 years ago

moll commented 10 years ago

Hey,

GlossyParser.prototype.parseBsdTime uses the new Date constructor passing it the current year in UTC, but new Date causes it then to be interpreted as the local time zone's year.

xegea commented 6 years ago

+1

xegea commented 6 years ago

I call this function as a workaround to save datetime correctly:

var currentDate = convertUTCDateToLocalDate(new Date(Date()));

function convertUTCDateToLocalDate(date) { date = new Date(date); var localOffset = date.getTimezoneOffset() * 60000; var localTime = date.getTime(); date = localTime - localOffset; date = new Date(date); return date; };