46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
|
var helpers = require("../helpers.js")
|
|||
|
|
|||
|
/*
|
|||
|
ZDA Time & Date – UTC, Day, Month, Year and Local Time Zone
|
|||
|
1 2 3 4 5 6 7
|
|||
|
| | | | | | |
|
|||
|
$--ZDA,hhmmss.ss,xx,xx,xxxx,xx,xx*hh
|
|||
|
1) Local zone minutes description, same sign as local hours
|
|||
|
2) Local zone description, 00 to +/- 13 hours
|
|||
|
3) Year
|
|||
|
4) Month, 01 to 12
|
|||
|
5) Day, 01 to 31
|
|||
|
6) Time (UTC)
|
|||
|
7) Checksum
|
|||
|
*/
|
|||
|
|
|||
|
exports.ID = 'ZDA';
|
|||
|
exports.TYPE = 'time-zone';
|
|||
|
|
|||
|
exports.decode = function(fields) {
|
|||
|
return {
|
|||
|
sentence: exports.ID,
|
|||
|
type: exports.TYPE,
|
|||
|
timestamp: fields[1],
|
|||
|
day: fields[2],
|
|||
|
month: fields[3],
|
|||
|
year: fields[4],
|
|||
|
ltzh: fields[5],
|
|||
|
ltzn: fields[6]
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
exports.encode = function (talker, msg) {
|
|||
|
var result = ['$' + talker + exports.ID];
|
|||
|
var { date } = msg
|
|||
|
result.push(helpers.padLeft(date.getHours().toString(), 2, '0') + helpers.padLeft(date.getMinutes().toString(), 2, '0') + helpers.padLeft(date.getSeconds().toString(), 2, '0') + '.000');
|
|||
|
result.push(helpers.padLeft(date.getDate().toString(), 2, '0'));
|
|||
|
result.push(helpers.padLeft((date.getMonth() + 1).toString(), 2, '0'));
|
|||
|
result.push(date.getFullYear().toString());
|
|||
|
result.push('00');
|
|||
|
result.push('00');
|
|||
|
|
|||
|
var resultMsg = result.join(',');
|
|||
|
return resultMsg + helpers.computeChecksum(resultMsg);
|
|||
|
}
|