Skip to content

Commit

Permalink
Add type datetime to path and path filter (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
godind authored Nov 27, 2023
1 parent 8c0fb81 commit 87f8259
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
32 changes: 31 additions & 1 deletion src/app/signalk.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ export interface pathRegistrationValue {
state: IZoneState;
};

// Validation of Signal K RFC3339S datetype format
const isRfc3339StringDate = (date: Date | string): boolean => {
if (isFinite(+(date instanceof Date ? date : new Date(date)))) {
let rfc3339 = new RegExp("^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$");
if (rfc3339.test(date as string)) {
return true;
} else {
return false;
}
} else {
return false;
}
};

/**
*
* @param {string} uuid The UUID for the widget registering the path
Expand Down Expand Up @@ -209,6 +223,13 @@ export class SignalKService {
}
if (this.paths[pathIndex].type == null) { // null means the path was first created to a Meta update. Meta updates don't contain source information so we set default source on first source data update.
this.paths[pathIndex].type = typeof(dataPath.value);

// set path data type to accommodate for SK datetype
if (typeof(dataPath.value) == "string") {
if (isRfc3339StringDate(dataPath.value)) {
this.paths[pathIndex].type = "Date";
}
}
}
this.paths[pathIndex].pathValue = dataPath.value; // we always push to both pat and source values
this.paths[pathIndex].sources[dataPath.source] = {
Expand All @@ -217,11 +238,20 @@ export class SignalKService {
};

} else { // doesn't exist. update...
let pathType: string = typeof(dataPath.value);

// set path data type to accommodate for SK datetype
if (typeof(dataPath.value) == "string") {
if (isRfc3339StringDate(dataPath.value)) {
pathType = "Date";
}
}

this.paths.push({
path: updatePath,
pathValue: dataPath.value,
defaultSource: dataPath.source,
type: typeof(dataPath.value),
type: pathType,
state: IZoneState.normal,
sources: {
[dataPath.source]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class WidgetDateGenericComponent extends BaseWidgetComponent implements O
dataTimestamp: number = Date.now();
valueFontSize = 1;

// length (in charaters) of value text to be displayed. if changed from last time, need to recalculate font size...
// length (in characters) of value text to be displayed. if changed from last time, need to recalculate font size...
currentValueLength = 0;
canvasCtx;
canvasBGCtx;
Expand All @@ -33,7 +33,7 @@ export class WidgetDateGenericComponent extends BaseWidgetComponent implements O
description: 'String Data',
path: null,
source: null,
pathType: 'string',
pathType: 'Date',
isPathConfigurable: true,
sampleTime: 500
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export class WidgetDateGenericComponent extends BaseWidgetComponent implements O
let valueText: string;

if (this.dataValue === null) {
valueText = 'Source Path not configured';
valueText = '--';
} else {

valueText = this.dataValue;
Expand Down

0 comments on commit 87f8259

Please sign in to comment.