Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ out

.DS_Store
version.sh
.idea
.idea

# vizualizer output
stats.html
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"@types/ua-parser-js": "^0.7.38",
"@types/uuid": "^9.0.1",
"@types/web": "^0.0.119",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
"js-cookie": "^3.0.5",
"react": "^17.0.2",
"react-dom": "^17.0.1",
"rollup": "^4.24.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.34.1",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.1.3",
"ua-parser-js": "^1.0.36",
"user-agent-data-types": "^0.3.1",
Expand All @@ -51,5 +51,6 @@
"@types/react": {
"optional": true
}
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
4 changes: 3 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sourcemaps from "rollup-plugin-sourcemaps"
import typescript from "rollup-plugin-typescript2"
import pkg from "./package.json"
import terser from "@rollup/plugin-terser"
import { visualizer } from "rollup-plugin-visualizer";

export default [
{
Expand Down Expand Up @@ -78,6 +79,7 @@ export default [
sourcemaps(),
typescript(),
terser(),
visualizer(),
]
}
]
]
25 changes: 16 additions & 9 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { v4 as uuidv4 } from 'uuid';
import Cookies from 'js-cookie';
import { BLOCKED_UAS } from '../constants';
import { format } from 'date-fns';
import { utcToZonedTime } from 'date-fns-tz';

export function getSaved(key: string) {
// first check if cookie exists
Expand Down Expand Up @@ -60,13 +58,22 @@ export function generateUserId() {
return uuidv4();
}

// export function getExactUTCTimeISO() {
// const nowUTC = moment().utc().format("YYYY-MM-DD HH:mm:ss.SSS");
// return nowUTC;
// }
export function getExactUTCTimeISO() {
const utcDate = utcToZonedTime(new Date(), 'Etc/UTC');
return format(utcDate, 'yyyy-MM-dd HH:mm:ss.SSS');
// get the current time
const localNow = new Date();
// the output of toISOString is always UTC.
// format is always: YYYY-MM-DDTHH:mm:ss.sssZ
// as long as we dont get to year 10000 any time soon.
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
const isoString = localNow.toISOString();
// the target format is yyyy-MM-dd HH:mm:ss.SSS
// we can safely replace the T with a space, since T will never be in the format
let outputString = isoString.replace('T', ' ');
// we can safely remove the Z at the end, as it will always be the last character
if(outputString.endsWith('Z')) {
outputString = outputString.substring(0, outputString.length - 1);
}
return outputString;
}

export function debugLog(message: string, debug: boolean) {
Expand Down Expand Up @@ -95,4 +102,4 @@ export function isBlockedUA() {
const userAgent = navigator.userAgent;
const ua = userAgent.toLowerCase();
return BLOCKED_UAS.some((b) => ua.includes(b));
}
}
Loading