| 1 47 | 2 48 | 3 49 | 4 50 | 5 | 1x 51 | 52 | 53 | 1x 54 | | // @flow
55 |
56 | export default function millisecondsUntil(date: Date): number {
57 | return date - Date.now();
58 | } |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 | 1x 63 | 64 | 65 | 1x 66 | 67 | 1x 68 | 1x 69 | 1x 70 | 1x 71 | 72 | 73 | 74 | 1x 75 | 76 | 1x 77 | 78 | | // @flow
79 |
80 | export default function getNextLunchtime(hours: number, minutes: number): Date {
81 | const lunchtime = new Date();
82 |
83 | lunchtime.setHours(hours);
84 | lunchtime.setMinutes(minutes);
85 | lunchtime.setSeconds(0);
86 | lunchtime.setMilliseconds(0);
87 |
88 | // if we've already had lunch today, start planning
89 | // tomorrow's lunch
90 | Eif (lunchtime < Date.now()) lunchtime.setDate(lunchtime.getDate() + 1);
91 |
92 | return lunchtime;
93 | }
94 | |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 | 1x 65 | 66 | 67 | 68 | 69 | 70 | 4x 71 | 72 | 1x 73 | 1x 74 | 1x 75 | 76 | 1x 77 | 78 | 1x 79 | 80 | 81 | 82 | | // @flow
83 |
84 | import React from 'react';
85 | import lunchtime from './lunchtime.js';
86 | import millisecondsUntil from './millisecondsUntil.js';
87 |
88 | import style from './main.scss';
89 |
90 | const HowLongTillLunch = ({ hours, minutes }: { hours: number, minutes: number }) => {
91 | Iif (hours === undefined) hours = 12;
92 | Iif (minutes === undefined) minutes = 30;
93 |
94 | const millisecondsUntilLunchTime = millisecondsUntil(lunchtime(hours, minutes));
95 |
96 | return <div className={style.goodLunch}>{millisecondsUntilLunchTime / 1000} seconds</div>;
97 | };
98 |
99 | export default HowLongTillLunch;
100 | |
| File | 50 |51 | | Statements | 52 |53 | | Branches | 54 |55 | | Functions | 56 |57 | | Lines | 58 |59 | |
|---|---|---|---|---|---|---|---|---|---|
| lunchtime.js | 63 |100% | 65 |10/10 | 66 |50% | 67 |1/2 | 68 |100% | 69 |1/1 | 70 |100% | 71 |8/8 | 72 ||
| main.js | 76 |77.78% | 78 |7/9 | 79 |75% | 80 |6/8 | 81 |100% | 82 |2/2 | 83 |100% | 84 |7/7 | 85 ||
| millisecondsUntil.js | 89 |100% | 91 |3/3 | 92 |100% | 93 |0/0 | 94 |100% | 95 |1/1 | 96 |100% | 97 |2/2 | 98 |