diff --git a/src/routes/uonetplus-wiadomosciplus.js b/src/routes/uonetplus-wiadomosciplus.js index 1032133..d8b3e87 100644 --- a/src/routes/uonetplus-wiadomosciplus.js +++ b/src/routes/uonetplus-wiadomosciplus.js @@ -1,7 +1,7 @@ const express = require('express'); const router = express.Router(); const protocol = require('../utils/connection'); -const {timestampToIsoTzFormat} = require('../utils/converter'); +const {timestampToIsoTzFormat, dateToTimestamp} = require('../utils/converter'); const {fromString} = require('uuidv4'); router.get("/", (req, res) => { @@ -38,12 +38,17 @@ router.get([ "/api/Odebrane", "/api/OdebraneSkrzynka", ], (req, res) => { - res.json(require("../../data/api/messages/WiadomosciOdebrane").map(item => { + const currentTimestamp = dateToTimestamp(new Date()); + res.json(require("../../data/api/messages/WiadomosciOdebrane").map((item, i) => { + let itemTimestamp = item.DataWyslaniaUnixEpoch; + if (i < 7) { + itemTimestamp = currentTimestamp - (i * i * 3600 * 6); + } return { "apiGlobalKey": fromString(item.WiadomoscId.toString()), "korespondenci": item.Nadawca + " - P - (123456)", "temat": item.Tytul, - "data": timestampToIsoTzFormat(item.DataWyslaniaUnixEpoch), + "data": timestampToIsoTzFormat(itemTimestamp), "skrzynka": "Jan Kowalski - U - (123456)", "hasZalaczniki": true, "przeczytana": !!item.GodzinaPrzeczytania, diff --git a/src/utils/converter.js b/src/utils/converter.js index 506fc23..8de197e 100644 --- a/src/utils/converter.js +++ b/src/utils/converter.js @@ -1,4 +1,4 @@ -const { addDays, toDate, format} = require('date-fns'); +const {addDays, toDate, format, getTime} = require('date-fns'); const WEEK_TICK = 6048000000000; const DAY_TICK = 864000000000; @@ -36,6 +36,10 @@ function timestampToIsoTzFormat(timestamp) { return format(new Date(timestamp * 1000), 'yyyy-MM-dd\'T\'HH:mm:ss.SSXXX'); } +function dateToTimestamp(date) { + return getTime(date) / 1000; +} + function getMonday(date) { let day = date.getDate() - date.getDay() + 1; return new Date(date.getFullYear(), date.getMonth(), day); @@ -96,3 +100,4 @@ exports.getPrevWeekTick = getPrevWeekTick; exports.getNextWeekTick = getNextWeekTick; exports.formatDate = formatDate; exports.timestampToIsoTzFormat = timestampToIsoTzFormat; +exports.dateToTimestamp = dateToTimestamp;