-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lwm2m): only include recent updates
- Loading branch information
1 parent
a9ece88
commit 30dac08
Showing
5 changed files
with
49 additions
and
5 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
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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, it } from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import { instanceTs } from './instanceTs.js' | ||
|
||
void describe('instanceTs()', () => { | ||
void it('should return the timestamp of the instance', () => | ||
assert.equal( | ||
instanceTs({ | ||
ObjectID: 14210, | ||
ObjectVersion: '1.0', | ||
Resources: { | ||
'0': 3.5399999618530273, | ||
'1': 4.168000221252441, | ||
'99': '2024-02-23T10:18:20.474Z', | ||
}, | ||
}).getTime(), | ||
new Date('2024-02-23T10:18:20.474Z').getTime(), | ||
)) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
type LwM2MObjectInstance, | ||
definitions, | ||
LwM2MObjectID, | ||
timestampResources, | ||
} from '@hello.nrfcloud.com/proto-lwm2m' | ||
|
||
export const instanceTs = (instance: LwM2MObjectInstance): Date => { | ||
const definition = definitions[instance.ObjectID as LwM2MObjectID] | ||
const tsResourceId = timestampResources[definition.ObjectID] as number | ||
const ts = instance.Resources[tsResourceId] as string | ||
return new Date(ts) | ||
} | ||
|
||
export const newestInstanceFirst = ( | ||
i1: LwM2MObjectInstance, | ||
i2: LwM2MObjectInstance, | ||
): number => instanceTs(i2).getTime() - instanceTs(i1).getTime() |