-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incoherent Date format #43
Comments
Proposal of fix in produce.js ...
msgData.push(generateDate(options.date, options.utc));
...
/*
* Generate date in RFC 3339 format. If no date is supplied, the default is
* the current time in GMT + 0.
* @param {Date} dateObject optional Date object
* @returns {String} formatted date
*/
function generateDate(dateObject, utc = false) {
if(!(dateObject instanceof Date)) dateObject = new Date(Date());
// Calcutate the offset
var timeOffset = 'Z';
var minutes = 0;
var hours = 0;
if (!utc) {
minutes = Math.abs(dateObject.getTimezoneOffset());
while(minutes >= 60) {
hours++;
minutes -= 60;
}
if(dateObject.getTimezoneOffset() < 0) {
// Ahead of UTC
timeOffset = '+' + leadZero(hours) + '' + ':' + leadZero(minutes);
} else if(dateObject.getTimezoneOffset() > 0) {
// Behind UTC
timeOffset = '-' + leadZero(hours) + '' + ':' + leadZero(minutes);
} else {
// UTC
timeOffset = 'Z';
}
}
// Date
formattedDate = dateObject.getUTCFullYear() + '-' +
// N.B. Javascript Date objects return months of the year indexed from
// zero, while the RFC 5424 syslog standard expects months indexed from
// one.
leadZero(dateObject.getUTCMonth() + 1) + '-' +
// N.B. Javascript Date objects return days of the month indexed from one
// (unlike months of year), so this does not need any correction.
leadZero(dateObject.getUTCDate()) + 'T' +
// Time
leadZero(utc ? dateObject.getUTCHours(): dateObject.getHours()) + ':' +
leadZero(utc ? dateObject.getUTCMinutes(): dateObject.getMinutes()) + ':' +
leadZero(utc ? dateObject.getUTCSeconds(): dateObject.getSeconds()) + '.' +
leadZero(utc ? dateObject.getUTCMilliseconds() : dateObject.getMilliseconds()) +
timeOffset;
return formattedDate;
} |
Any chance this is going to get merged? |
I wonder if this was fixed already with #34 ? It was merged on 2016-01-11, but the last glossy release (0.1.7) was in 2014. So it's quite possible this is already fixed. I checked NPM and there's one newer fork of glossy that fixed the issue for me: https://www.npmjs.com/package/@myndzi/glossy
|
... unfortunately I just saw
I'm guessing |
... okay, I figured out a way to work around that too; there's yet another fork where that's fixed (https://github.com/pavkriz/glossy). It's not published on NPM, but apparently NPM can actually install from a git repo:
|
Standard JS Date is displaying:
You can notice, than when the time zone is displayed, the hour value is upgraded accordingly.
In glossy, by using 'RFC5424', the generateDate function code in produce.js is leading to generate:
2019-10-11T08:46:11.515+02:00 while the locale time was 10:46
Two options should be supported and could be chosen through options:
The text was updated successfully, but these errors were encountered: