Fix datetime format in messages plus

This commit is contained in:
Mikołaj Pich 2022-08-30 00:00:52 +02:00
parent 63ff665a82
commit 37e21710ca
2 changed files with 12 additions and 6 deletions

View file

@ -1,6 +1,7 @@
const express = require('express');
const router = express.Router();
const protocol = require('../utils/connection');
const {timestampToIsoTzFormat} = require('../utils/converter');
const {fromString} = require('uuidv4');
router.get("/", (req, res) => {
@ -42,7 +43,7 @@ router.get([
"apiGlobalKey": fromString(item.WiadomoscId.toString()),
"korespondenci": item.Nadawca + " - P - (123456)",
"temat": item.Tytul,
"data": new Date(item.DataWyslaniaUnixEpoch * 1000).toISOString(),
"data": timestampToIsoTzFormat(item.DataWyslaniaUnixEpoch),
"skrzynka": "Jan Kowalski - U - (123456)",
"hasZalaczniki": true,
"przeczytana": !!item.GodzinaPrzeczytania,
@ -63,7 +64,7 @@ router.get([
"apiGlobalKey": fromString(item.WiadomoscId.toString()),
"korespondenci": item.Nadawca + " - P - (123456)",
"temat": item.Tytul,
"data": new Date(item.DataWyslaniaUnixEpoch * 1000).toISOString(),
"data": timestampToIsoTzFormat(item.DataWyslaniaUnixEpoch),
"skrzynka": "Jan Kowalski - U - (123456)",
"hasZalaczniki": true,
"przeczytana": !!item.GodzinaPrzeczytania,
@ -84,7 +85,7 @@ router.get([
"apiGlobalKey": fromString(item.WiadomoscId.toString()),
"korespondenci": item.Nadawca + " - P - (123456)",
"temat": item.Tytul,
"data": new Date(item.DataWyslaniaUnixEpoch * 1000).toISOString(),
"data": timestampToIsoTzFormat(item.DataWyslaniaUnixEpoch),
"skrzynka": "Jan Kowalski - U - (123456)",
"hasZalaczniki": true,
"przeczytana": !!item.GodzinaPrzeczytania,
@ -110,7 +111,7 @@ router.get("/api/Skrzynki", (req, res) => {
router.all("/api/WiadomoscSzczegoly", (req, res) => {
const message = require("../../data/api/messages/WiadomosciOdebrane")[0];
res.json({
"data": new Date(message.DataWyslaniaUnixEpoch * 1000).toISOString(),
"data": timestampToIsoTzFormat(message.DataWyslaniaUnixEpoch),
"apiGlobalKey": fromString(message.WiadomoscId.toString()),
"nadawca": "Natalia Wrzesień - P - (123456)",
"odbiorcy": ["Jan kowalski - U - (123456)"],
@ -139,7 +140,7 @@ router.all("/api/WiadomoscOdpowiedzPrzekaz", (req, res) => {
const user = require("../../data/api/ListaUczniow")[1];
const message = require("../../data/api/messages/WiadomosciOdebrane")[0];
res.json({
"data": new Date(message.DataWyslaniaUnixEpoch * 1000).toISOString(),
"data": timestampToIsoTzFormat(message.DataWyslaniaUnixEpoch),
"apiGlobalKey": fromString(message.WiadomoscId.toString()),
"uzytkownikSkrzynkaGlobalKey": fromString(user.Id.toString()),
"nadawcaSkrzynkaGlobalKey": fromString(message.NadawcaId.toString()),

View file

@ -1,4 +1,4 @@
const { addDays, toDate } = require('date-fns');
const { addDays, toDate, format} = require('date-fns');
const WEEK_TICK = 6048000000000;
const DAY_TICK = 864000000000;
@ -32,6 +32,10 @@ function formatDate(today, iso = false) {
return `${dd}.${mm}.${yyyy}`;
}
function timestampToIsoTzFormat(timestamp) {
return format(new Date(timestamp * 1000), 'yyyy-MM-dd\'T\'HH:mm:ss.SSXXX');
}
function getMonday(date) {
let day = date.getDate() - date.getDay() + 1;
return new Date(date.getFullYear(), date.getMonth(), day);
@ -91,3 +95,4 @@ exports.getNextDayTick = getNextDayTick;
exports.getPrevWeekTick = getPrevWeekTick;
exports.getNextWeekTick = getNextWeekTick;
exports.formatDate = formatDate;
exports.timestampToIsoTzFormat = timestampToIsoTzFormat;