Skip to content
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

Update the Date in case it's before 2020 due to lapped old GPS. #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pgns/129029.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const debug = require('debug')('n2k-signalk-129029')

function pad2 (number) {
return number < 10 ? '0' + number : number
}

module.exports = [
{
value: function (n2k) {
Expand All @@ -13,6 +19,21 @@ module.exports = [
},
{
value: function (n2k) {
// Check if the year is less than 2024
let [year, month, day] = n2k.fields.Date.split('.').map(Number)
if (year < 2020) {
// Create a date object from the extracted values
let date = new Date(Date.UTC(year, month - 1, day))

// Add 7168 days to the date
date.setDate(date.getDate() + 7168)

// Update the value with the new date
n2k.fields.Date = `${date.getUTCFullYear()}.${pad2(
date.getUTCMonth() + 1
)}.${pad2(date.getUTCDate())}`
}

return `${n2k.fields.Date.replace(/\./g, '-')}T${n2k.fields.Time}Z`
},
filter: n2k =>
Expand Down
Loading