Skip to content

Commit

Permalink
feat(app): switch to luxon for timestamp creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zweihander-Main committed Oct 30, 2023
1 parent d8d404a commit 10cda83
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"author": "Zweihänder",
"license": "AGPL-3.0",
"dependencies": {
"@types/express": "^4.17.19",
"@types/node": "^20.8.5",
"@types/node-cron": "^3.0.9",
"@types/rss": "^0.0.30",
"@types/yargs": "^17.0.28",
"@types/express": "^4.17.19",
"axios": "^1.5.1",
"express": "^4.18.2",
"liquidjs": "^10.9.2",
"luxon": "^3.4.3",
"moment": "^2.29.4",
"node-cron": "^3.0.2",
"rss": "^1.2.2",
Expand All @@ -29,6 +30,7 @@
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/luxon": "^3.3.3",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"eslint": "^8.51.0",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 39 additions & 14 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Liquid } from 'liquidjs';
import yargs from 'yargs/yargs';
import express from 'express';
import cron from 'node-cron';
import { DateTime } from 'luxon';

const TIMESTAMP_HOUR = 10;
const TIMESTAMP_MINUTE = 0;
Expand Down Expand Up @@ -77,26 +78,48 @@ const liquidEngine = new Liquid({
});

const createTimeStampData = () => {
const currentTime = new Date();
const t24HrAgo = new Date();
const t12HrAgo = new Date();
if (currentTime.getHours() < 12) {
const currentTime = DateTime.now().setZone(TIMEZONE);
let t24HrAgo = currentTime.minus({ hours: 24 });
let t12HrAgo = currentTime.minus({ hours: 12 });
if (currentTime.hour < 12) {
// Before noon
t24HrAgo.setDate(t24HrAgo.getDate() - 1);
t24HrAgo.setHours(TIMESTAMP_HOUR, TIMESTAMP_MINUTE, 0, 0);
t12HrAgo.setDate(t12HrAgo.getDate() - 1);
t12HrAgo.setHours(TIMESTAMP_HOUR + 12, TIMESTAMP_MINUTE, 0, 0);
t24HrAgo = t24HrAgo.minus({ days: 1 }).set({
hour: TIMESTAMP_HOUR,
minute: TIMESTAMP_MINUTE,
second: 0,
millisecond: 0,
});
t12HrAgo = t12HrAgo.minus({ days: 1 }).set({
hour: TIMESTAMP_HOUR + 12,
minute: TIMESTAMP_MINUTE,
second: 0,
millisecond: 0,
});
} else {
// After noon
t24HrAgo.setDate(t24HrAgo.getDate() - 1);
t24HrAgo.setHours(TIMESTAMP_HOUR + 12, TIMESTAMP_MINUTE, 0, 0);
t12HrAgo.setHours(TIMESTAMP_HOUR, TIMESTAMP_MINUTE, 0, 0);
t24HrAgo = t24HrAgo.minus({ days: 1 }).set({
hour: TIMESTAMP_HOUR + 12,
minute: TIMESTAMP_MINUTE,
second: 0,
millisecond: 0,
});
t12HrAgo = t12HrAgo.set({
hour: TIMESTAMP_HOUR,
minute: TIMESTAMP_MINUTE,
second: 0,
millisecond: 0,
});
}
const returnData = {
t24HrAgo: t24HrAgo.getTime() / 1000,
t12HrAgo: t12HrAgo.getTime() / 1000,
t24HrAgo: t24HrAgo.toSeconds(),
t12HrAgo: t12HrAgo.toSeconds(),
};
console.log('Created timestamp for:', returnData);
console.log(
'Timestamp will be from',
t24HrAgo.toString(),
'to',
t12HrAgo.toString()
);
return returnData;
};

Expand Down Expand Up @@ -251,13 +274,15 @@ const createRSSFeed = async (start?: number, end?: number) => {

const xml = feed.xml({ indent: true });
writeFeedFile(xml);
console.log('Created new RSS feed');
return;
};

const createDummyRSSFeed = () => {
const feed = new RSS(feedData);
const xml = feed.xml({ indent: true });
writeFeedFile(xml);
console.log('Created dummy RSS feed');
return;
};

Expand Down

0 comments on commit 10cda83

Please sign in to comment.