aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/lib
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-29 16:31:05 +0100
committerGitHub <noreply@github.com>2018-01-29 16:31:05 +0100
commit694580bc532239a32c2fbf61d7f09e793fd1cb11 (patch)
treeacd21e2654d6c5e70dc41c675972794ce95b4062 /src/client/react/lib
parentf18692872cdc28d29917247ef4f8ef7553a8b023 (diff)
parent9a9edd1865d619caada787231c8bb34be25af3af (diff)
Merge pull request #15 from nloomans/react
Move project over to react
Diffstat (limited to 'src/client/react/lib')
-rw-r--r--src/client/react/lib/extractSchedule.js10
-rw-r--r--src/client/react/lib/purifyWeek.js9
2 files changed, 19 insertions, 0 deletions
diff --git a/src/client/react/lib/extractSchedule.js b/src/client/react/lib/extractSchedule.js
new file mode 100644
index 0000000..e74411b
--- /dev/null
+++ b/src/client/react/lib/extractSchedule.js
@@ -0,0 +1,10 @@
+export default function extractSchedule(schedules, user, week) {
+ const scheduleExists =
+ schedules.hasOwnProperty(user) && schedules[user].hasOwnProperty(week);
+
+ if (!scheduleExists) {
+ return { state: 'NOT_REQUESTED' };
+ }
+
+ return schedules[user][week];
+}
diff --git a/src/client/react/lib/purifyWeek.js b/src/client/react/lib/purifyWeek.js
new file mode 100644
index 0000000..939f5af
--- /dev/null
+++ b/src/client/react/lib/purifyWeek.js
@@ -0,0 +1,9 @@
+import moment from 'moment';
+
+export default function purifyWeek(week) {
+ // This ensures that week 0 will become week 52 and that week 53 will become
+ // week 1. This also accounts for leap years. Because date logic can be so
+ // complicated we off load it to moment.js so that we can be sure it's bug
+ // free.
+ return moment().week(week).week();
+}