Parse lastStamp as Date in AvailabilityService
Type AvailabilityInfo.lastStamp as Date and convert from the JSON string in the service after fetch, so consumers work with real Date objects.
This commit is contained in:
@@ -2,6 +2,6 @@ export class AvailabilityInfo {
|
|||||||
public user: string;
|
public user: string;
|
||||||
public loggedIn: boolean;
|
public loggedIn: boolean;
|
||||||
public extension: string;
|
public extension: string;
|
||||||
public lastStamp: string;
|
public lastStamp: Date;
|
||||||
public firma: boolean;
|
public firma: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,11 @@ export class AvailabilityService {
|
|||||||
try {
|
try {
|
||||||
var response = await GM_fetch(Config.tapi_server_url + '/availability')
|
var response = await GM_fetch(Config.tapi_server_url + '/availability')
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this._availabilities = await response.json() as AvailabilityInfo[]
|
var raw = await response.json() as AvailabilityInfo[]
|
||||||
|
this._availabilities = raw.map(a => ({
|
||||||
|
...a,
|
||||||
|
lastStamp: a.lastStamp ? new Date(a.lastStamp) : null,
|
||||||
|
}))
|
||||||
this._listeners.forEach(l => l(this._availabilities))
|
this._listeners.forEach(l => l(this._availabilities))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ export class Availability {
|
|||||||
var dotClass = entry.loggedIn ? 'tapi-dot-on' : 'tapi-dot-off'
|
var dotClass = entry.loggedIn ? 'tapi-dot-on' : 'tapi-dot-off'
|
||||||
var time = ''
|
var time = ''
|
||||||
if (entry.lastStamp) {
|
if (entry.lastStamp) {
|
||||||
var d = new Date(entry.lastStamp)
|
|
||||||
var pad = (n: number) => n.toString().padStart(2, '0')
|
var pad = (n: number) => n.toString().padStart(2, '0')
|
||||||
|
var d = entry.lastStamp
|
||||||
time = pad(d.getDate()) + '.' + pad(d.getMonth() + 1) + '. ' + pad(d.getHours()) + ':' + pad(d.getMinutes())
|
time = pad(d.getDate()) + '.' + pad(d.getMonth() + 1) + '. ' + pad(d.getHours()) + ':' + pad(d.getMinutes())
|
||||||
}
|
}
|
||||||
var location = ''
|
var location = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user