diff --git a/package.json b/package.json index e279d8df72541507596d18bdb8361c68fa5ff03a..5c85d209240d059393329cb772c933150f6eb150 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,6 @@ "event-target-shim": "^3.0.1", "form-urlencoded": "^2.0.4", "jsonschema": "^1.2.2", - "moment": "^2.22.0", - "moment-timezone": "^0.5.14", "moving-average": "^1.0.0", "naf-janus-adapter": "^0.10.1", "networked-aframe": "https://github.com/mozillareality/networked-aframe#mr-social-client/master", diff --git a/src/hub.js b/src/hub.js index d66de1f4ffae134ee535e1bc6b38a4baf562f9e7..06c38f5181e2dda8b97307afd2bb0e8fd73698a3 100644 --- a/src/hub.js +++ b/src/hub.js @@ -1,5 +1,4 @@ import "./assets/stylesheets/hub.scss"; -import moment from "moment-timezone"; import queryString from "query-string"; import { patchWebGLRenderingContext } from "./utils/webgl"; @@ -334,7 +333,7 @@ const onReady = async () => { document.body.addEventListener("connected", () => { if (!isBotMode) { hubChannel.sendEntryEvent().then(() => { - store.update({ activity: { lastEnteredAt: moment().toJSON() } }); + store.update({ activity: { lastEnteredAt: new Date().toISOString() } }); }); } remountUI({ occupantCount: NAF.connection.adapter.publisher.initialOccupants.length + 1 }); diff --git a/src/utils/hub-channel.js b/src/utils/hub-channel.js index aad95ec4e7550ff29181789b9e8a8c299f8961db..d8b87730a98dea1feb8f98793323d4b74a139553 100644 --- a/src/utils/hub-channel.js +++ b/src/utils/hub-channel.js @@ -1,4 +1,13 @@ -import moment from "moment-timezone"; +const MS_PER_DAY = 1000 * 60 * 60 * 24; +const MS_PER_MONTH = 1000 * 60 * 60 * 24 * 30; + +function isSameMonth(da, db) { + return da.getFullYear() == db.getFullYear() && da.getMonth() == db.getMonth(); +} + +function isSameDay(da, db) { + return isSameMonth(da, db) && da.getDate() == db.getDate(); +} export default class HubChannel { constructor(store) { @@ -52,18 +61,15 @@ export default class HubChannel { return entryTimingFlags; } - const lastEntered = moment(storedLastEnteredAt); - const lastEnteredPst = moment(lastEntered).tz("America/Los_Angeles"); - const nowPst = moment().tz("America/Los_Angeles"); - const dayWindowAgo = moment().subtract(1, "day"); - const monthWindowAgo = moment().subtract(1, "month"); - - entryTimingFlags.isNewDaily = - lastEnteredPst.dayOfYear() !== nowPst.dayOfYear() || lastEnteredPst.year() !== nowPst.year(); - entryTimingFlags.isNewMonthly = - lastEnteredPst.month() !== nowPst.month() || lastEnteredPst.year() !== nowPst.year(); - entryTimingFlags.isNewDayWindow = lastEntered.isBefore(dayWindowAgo); - entryTimingFlags.isNewMonthWindow = lastEntered.isBefore(monthWindowAgo); + const now = new Date(); + const lastEntered = new Date(storedLastEnteredAt); + const msSinceLastEntered = now - lastEntered; + + // note that new daily and new monthly is based on client local time + entryTimingFlags.isNewDaily = !isSameDay(now, lastEntered); + entryTimingFlags.isNewMonthly = !isSameMonth(now, lastEntered); + entryTimingFlags.isNewDayWindow = msSinceLastEntered > MS_PER_DAY; + entryTimingFlags.isNewMonthWindow = msSinceLastEntered > MS_PER_MONTH; return entryTimingFlags; }; diff --git a/yarn.lock b/yarn.lock index c939afe917e5369790d07356d6301e7e1de75e88..6783d21e029245a2a0582351a0f119232f27df17 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5406,16 +5406,6 @@ module-deps@^6.0.0: through2 "^2.0.0" xtend "^4.0.0" -moment-timezone@^0.5.14: - version "0.5.14" - resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.14.tgz#4eb38ff9538b80108ba467a458f3ed4268ccfcb1" - dependencies: - moment ">= 2.9.0" - -"moment@>= 2.9.0", moment@^2.22.0: - version "2.22.0" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.0.tgz#7921ade01017dd45186e7fee5f424f0b8663a730" - move-concurrently@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"