Skip to content

Instantly share code, notes, and snippets.

@slayerlab
Created June 13, 2018 23:00
Show Gist options
  • Save slayerlab/a8b5c60f5053b203d9fe95f9384aeef0 to your computer and use it in GitHub Desktop.
Save slayerlab/a8b5c60f5053b203d9fe95f9384aeef0 to your computer and use it in GitHub Desktop.
[PoC, NodeJS] A workaround to convert time from NVDCVE feed to SecurityFocus.
#!/usr/bin/node
'use strict';
String.prototype.bidTimeConvert = function () {
let month = ['Jan', 'Feb', 'Mar', 'Apr', 'Mar', 'May', 'Jun', 'Jul', 'Ago', 'Set', 'Oct', 'Nov', 'Dec'];
let fromTime = new Date(this.toString().split('.')[0]).toLocaleString();
let fromMinutes = ((new Date(fromTime).getMinutes()).toString().length == 1) ? '0'+new Date(fromTime).getMinutes() : new Date(fromTime).getMinutes();
return (new Date(fromTime).getHours() < 12)
? month[new Date(fromTime).getMonth()+1] +' '+new Date(fromTime).getDate()+' '+new Date(fromTime).getFullYear()+' '+(new Date(fromTime).getHours() + 12)+':'+fromMinutes+'AM'
: month[new Date(fromTime).getMonth()+1] +' '+new Date(fromTime).getDate()+' '+new Date(fromTime).getFullYear()+' '+new Date(fromTime).getHours()+':'+fromMinutes+'PM';
}
console.log('1998-07-20T00:00:00.000-04:00'.bidTimeConvert());
console.log('2008-09-05T16:16:20.580-04:00'.bidTimeConvert());
console.log('2006-05-01T12:00:00.000-04:00'.bidTimeConvert());
@slayerlab
Copy link
Author

Output:

$ node bidTimeConvert.js 
Jul 20 1998 12:00AM
Set 5 2008 16:16PM
May 1 2006 12:00PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment