-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use parseIntSafe and some minor fixes
- Loading branch information
Showing
2 changed files
with
21 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
/* | ||
* === GST - UTC day, month, and year, and local time zone offset === | ||
* === ZDA - Time & Date - UTC, day, month, year and local time zone === | ||
* | ||
* ------------------------------------------------------------------------------ | ||
* 1 2 3 4 5 6 7 | ||
* | | | | | | | | ||
* $--GST,hhmmss.ss,dd,mm,yyyy,zz,zz,*hh<CR><LF> | ||
* 1 2 3 4 5 6 7 | ||
* | | | | | | | | ||
* $--ZDA,hhmmss.ss,dd,mm,yyyy,zz,zz*hh<CR><LF> | ||
* ------------------------------------------------------------------------------ | ||
* | ||
* Field Number: | ||
* 1. UTC time | ||
* 2. Day, ranging between 01 and 31 | ||
* 3. Month, ranging between 01 and 12 | ||
* 4. Year | ||
* 5. Local time zone offset from GMT, ranging from 00 through ±13 hours | ||
* 6. Local time zone offset from GMT, ranging from 00 through 59 minutes | ||
* 1. UTC time (hours, minutes, seconds, may have fractional subsecond) | ||
* 2. Day, 01 to 31 | ||
* 3. Month, 01 to 12 | ||
* 4. Year (4 digits) | ||
* 5. Local zone description, 00 to +- 13 hours | ||
* 6. Local zone minutes description, 00 to 59, apply same sign as local hours | ||
* 7. Checksum | ||
*/ | ||
|
||
import { parseTime } from "../helpers"; | ||
import { parseIntSafe, parseTime } from "../helpers"; | ||
|
||
export const sentenceId: "ZDA" = "ZDA"; | ||
export const sentenceName = "Data and Time"; | ||
export const sentenceName = "UTC, day, month, year, and local time zone"; | ||
|
||
export interface ZDAPacket { | ||
sentenceId: "ZDA"; | ||
sentenceName: string; | ||
talkerId?: string; | ||
datetime: Date; | ||
localHoursOffset: number; | ||
localMinutesOffset: number; | ||
localZoneHours: number; | ||
localZoneMinutes: number; | ||
} | ||
|
||
export function decodeSentence(fields: string[]): ZDAPacket { | ||
return { | ||
sentenceId: sentenceId, | ||
sentenceName: sentenceName, | ||
datetime: parseTime(fields[1], fields.slice(2, 5).join("")), | ||
localHoursOffset: parseInt(fields[5], 10), | ||
localMinutesOffset: parseInt(fields[6], 10) | ||
localZoneHours: parseIntSafe(fields[5]), | ||
localZoneMinutes: parseIntSafe(fields[6]) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters