Skip to content

Commit

Permalink
Remove moment as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mqp committed Jul 17, 2018
1 parent caad5c0 commit b8529d9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
"form-urlencoded": "^2.0.4",
"jsonschema": "^1.2.2",
"mobile-detect": "^1.4.1",
"moment": "^2.22.0",
"moment-timezone": "^0.5.14",
"moving-average": "^1.0.0",
"naf-janus-adapter": "^0.9.0",
"networked-aframe": "https://github.com/mozillareality/networked-aframe#mr-social-client/master",
Expand Down
3 changes: 1 addition & 2 deletions src/hub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "./assets/stylesheets/hub.scss";
import moment from "moment-timezone";
import queryString from "query-string";

import { patchWebGLRenderingContext } from "./utils/webgl";
Expand Down Expand Up @@ -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 });
Expand Down
32 changes: 19 additions & 13 deletions src/utils/hub-channel.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
};
Expand Down
8 changes: 7 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class LodashTemplatePlugin {
}

const config = {
resolve: {
"alias": {
"react": "preact-compat",
"react-dom": "preact-compat"
}
},
entry: {
index: path.join(__dirname, "src", "index.js"),
hub: path.join(__dirname, "src", "hub.js"),
Expand All @@ -97,7 +103,7 @@ const config = {
https: createHTTPSConfig(),
host: "0.0.0.0",
useLocalIp: true,
public: "hubs.local:8080",
public: "10.252.25.129:8080",
port: 8080,
headers: { "Access-Control-Allow-Origin": "*" },
before: function(app) {
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5410,16 +5410,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"
Expand Down

0 comments on commit b8529d9

Please sign in to comment.