Make received messages dates more dynamic
This commit is contained in:
parent
aec541ff35
commit
8321043cdd
2 changed files with 14 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const protocol = require('../utils/connection');
|
const protocol = require('../utils/connection');
|
||||||
const {timestampToIsoTzFormat} = require('../utils/converter');
|
const {timestampToIsoTzFormat, dateToTimestamp} = require('../utils/converter');
|
||||||
const {fromString} = require('uuidv4');
|
const {fromString} = require('uuidv4');
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req, res) => {
|
||||||
|
@ -38,12 +38,17 @@ router.get([
|
||||||
"/api/Odebrane",
|
"/api/Odebrane",
|
||||||
"/api/OdebraneSkrzynka",
|
"/api/OdebraneSkrzynka",
|
||||||
], (req, res) => {
|
], (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 {
|
return {
|
||||||
"apiGlobalKey": fromString(item.WiadomoscId.toString()),
|
"apiGlobalKey": fromString(item.WiadomoscId.toString()),
|
||||||
"korespondenci": item.Nadawca + " - P - (123456)",
|
"korespondenci": item.Nadawca + " - P - (123456)",
|
||||||
"temat": item.Tytul,
|
"temat": item.Tytul,
|
||||||
"data": timestampToIsoTzFormat(item.DataWyslaniaUnixEpoch),
|
"data": timestampToIsoTzFormat(itemTimestamp),
|
||||||
"skrzynka": "Jan Kowalski - U - (123456)",
|
"skrzynka": "Jan Kowalski - U - (123456)",
|
||||||
"hasZalaczniki": true,
|
"hasZalaczniki": true,
|
||||||
"przeczytana": !!item.GodzinaPrzeczytania,
|
"przeczytana": !!item.GodzinaPrzeczytania,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { addDays, toDate, format} = require('date-fns');
|
const {addDays, toDate, format, getTime} = require('date-fns');
|
||||||
const WEEK_TICK = 6048000000000;
|
const WEEK_TICK = 6048000000000;
|
||||||
const DAY_TICK = 864000000000;
|
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');
|
return format(new Date(timestamp * 1000), 'yyyy-MM-dd\'T\'HH:mm:ss.SSXXX');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dateToTimestamp(date) {
|
||||||
|
return getTime(date) / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
function getMonday(date) {
|
function getMonday(date) {
|
||||||
let day = date.getDate() - date.getDay() + 1;
|
let day = date.getDate() - date.getDay() + 1;
|
||||||
return new Date(date.getFullYear(), date.getMonth(), day);
|
return new Date(date.getFullYear(), date.getMonth(), day);
|
||||||
|
@ -96,3 +100,4 @@ exports.getPrevWeekTick = getPrevWeekTick;
|
||||||
exports.getNextWeekTick = getNextWeekTick;
|
exports.getNextWeekTick = getNextWeekTick;
|
||||||
exports.formatDate = formatDate;
|
exports.formatDate = formatDate;
|
||||||
exports.timestampToIsoTzFormat = timestampToIsoTzFormat;
|
exports.timestampToIsoTzFormat = timestampToIsoTzFormat;
|
||||||
|
exports.dateToTimestamp = dateToTimestamp;
|
||||||
|
|
Loading…
Reference in a new issue