* TZUTC/TZUTCINFO handling should work properly

* Don't bork message timestamp when we write to the DB
* Fix read byte len which could prevent message imports!
This commit is contained in:
Bryan Ashby 2020-11-17 19:06:54 -07:00
parent b377d91155
commit 8b2be6769c
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
2 changed files with 24 additions and 8 deletions

View File

@ -678,11 +678,28 @@ function Packet(options) {
} }
// //
// If we have a UTC offset kludge (e.g. TZUTC) then update // Attempt to handle FTN time zone kludges of 'TZUTC' and
// modDateTime with it // 'TZUTCINFO'.
// //
if(_.isString(msg.meta.FtnKludge.TZUTC) && msg.meta.FtnKludge.TZUTC.length > 0) { // See http://ftsc.org/docs/frl-1004.002
msg.modDateTime = msg.modTimestamp.utcOffset(msg.meta.FtnKludge.TZUTC); //
const tzKludge = msg.meta.FtnKludge.TZUTC || msg.meta.FtnKludge.TZUTCINFO;
const tzMatch = /([+-]?)([0-9]{2})([0-9]{2})/.exec(tzKludge);
if (tzMatch) {
//
// - Both kludges should provide a offset in hhmm format
// - Negative offsets must proceed with '-'
// - Positive offsets must not (to spec) proceed with '+', but
// we'll allow it.
//
const [, sign, hours, minutes ] = tzMatch;
// convert to a [+|-]hh:mm format.
// example: 1300 -> +13:00
const utcOffset = `${sign||'+'}${hours}:${minutes}`;
// finally, update our modTimestamp
msg.modTimestamp = msg.modTimestamp.utcOffset(utcOffset);
} }
// :TODO: Parser should give is this info: // :TODO: Parser should give is this info:

View File

@ -134,7 +134,7 @@ module.exports = class Message {
modTimestamp = moment(modTimestamp); modTimestamp = moment(modTimestamp);
} }
this.modTimestamp = modTimestamp; this.modTimestamp = modTimestamp || moment();
this.meta = {}; this.meta = {};
_.defaultsDeep(this.meta, { System : {} }, meta); _.defaultsDeep(this.meta, { System : {} }, meta);
@ -695,11 +695,10 @@ module.exports = class Message {
}, },
function storeMessage(trans, callback) { function storeMessage(trans, callback) {
// generate a UUID for this message if required (general case) // generate a UUID for this message if required (general case)
const msgTimestamp = moment();
if(!self.messageUuid) { if(!self.messageUuid) {
self.messageUuid = Message.createMessageUUID( self.messageUuid = Message.createMessageUUID(
self.areaTag, self.areaTag,
msgTimestamp, self.modTimestamp,
self.subject, self.subject,
self.message self.message
); );
@ -710,7 +709,7 @@ module.exports = class Message {
VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, VALUES (?, ?, ?, ?, ?, ?, ?, ?);`,
[ [
self.areaTag, self.messageUuid, self.replyToMsgId, self.toUserName, self.areaTag, self.messageUuid, self.replyToMsgId, self.toUserName,
self.fromUserName, self.subject, self.message, getISOTimestampString(msgTimestamp) self.fromUserName, self.subject, self.message, getISOTimestampString(self.modTimestamp)
], ],
function inserted(err) { // use non-arrow function for 'this' scope function inserted(err) { // use non-arrow function for 'this' scope
if(!err) { if(!err) {