Skip to content

Commit 06e6139

Browse files
author
Viper
committed
Date (locales) improvement
* Date picker range * Chart first day of the week
1 parent 01ebc1e commit 06e6139

File tree

7 files changed

+193
-11
lines changed

7 files changed

+193
-11
lines changed

404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
<body>
6262
<div id="app"></div>
63-
<script src="/client.min.js?v=12.16"></script>
63+
<script src="/client.min.js?v=12.17"></script>
6464
</body>
6565

6666
</html>

client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@
6060

6161
<body>
6262
<div id="app"></div>
63-
<script src="/client.min.js?v=12.16"></script>
63+
<script src="/client.min.js?v=12.17"></script>
6464
</body>
6565
</html>

service-worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var CACHE = "network-or-cache-v12.16";
1+
var CACHE = "network-or-cache-v12.17";
22

33
// On install, cache some resource.
44
self.addEventListener("install", function(evt) {
@@ -10,7 +10,7 @@ self.addEventListener("install", function(evt) {
1010
cache.addAll([
1111
"/",
1212
"/404.html",
13-
"/client.min.js?v=12.16",
13+
"/client.min.js?v=12.17",
1414
"src/fonts/Cantarell-Regular.ttf",
1515
"src/fonts/OpenSans-Regular.ttf",
1616
"src/fonts/Saira-Regular.ttf",

src/js/components/CoinChartsChart.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import Skeleton from "@material-ui/lab/Skeleton";
1414
import ChartDot from "../icons/ChartDot";
1515

1616
import { scaleTime } from "d3-scale";
17-
import {utcHour, utcDay, utcMonth, utcWeek, utcYear} from "d3-time";
17+
import {utcHour, utcDay, utcMonth, utcWeek, utcYear, utcMonday, utcFriday, utcSaturday, utcSunday} from "d3-time";
18+
19+
import { FIRST_WEEK_DAY_BY_COUNTRY } from "../utils/constants";
1820

1921
import { ResponsiveContainer, AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip } from "recharts";
2022
import price_formatter from "../utils/price-formatter";
@@ -247,7 +249,8 @@ class CoinChartsChart extends React.Component {
247249

248250
_get_coin_chart_data_ticks = (graph_data, coin_chart_data_time) => {
249251

250-
if (!graph_data || !graph_data.length ) {return [];}
252+
const { selected_locales_code } = this.state;
253+
if (!graph_data || !graph_data.length || !selected_locales_code) {return [];}
251254

252255
const domain = [new Date(+graph_data[0].date), new Date(+graph_data[graph_data.length - 1].date)];
253256
const scale = scaleTime().domain(domain).range([0, 1]);
@@ -267,7 +270,25 @@ class CoinChartsChart extends React.Component {
267270
return ticks.map(entry => +entry);
268271
case "30":
269272

270-
ticks = scale.ticks(utcWeek, 1);
273+
let utc_day = utcWeek;
274+
275+
switch(FIRST_WEEK_DAY_BY_COUNTRY[selected_locales_code.split("-")[1] || "US"]) {
276+
277+
case "mon":
278+
utc_day = utcMonday;
279+
break;
280+
case "fri":
281+
utc_day = utcFriday;
282+
break;
283+
case "sat":
284+
utc_day = utcSaturday;
285+
break;
286+
case "sun":
287+
utc_day = utcSunday;
288+
break;
289+
}
290+
291+
ticks = scale.ticks(utc_day, 1);
271292
return ticks.map(entry => +entry);
272293
case "180":
273294

src/js/components/CoinChartsConvert.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CoinChartsConvert extends React.Component {
4343
selected_locales_code: props.selected_locales_code,
4444
selected_currency: props.selected_currency,
4545
coin_data: props.coin_data,
46+
_min_date: new Date(),
4647
_selected_date: new Date(),
4748
_cryptocurrency_input_value: 1,
4849
_selected_cryptocurrency_price: 0,
@@ -73,6 +74,8 @@ class CoinChartsConvert extends React.Component {
7374

7475
if(!error && results !== null) {
7576

77+
const _min_date = results.prices[0].date;
78+
7679
for (let i = 0; i < results.prices.length; i++) {
7780

7881
const result = results.prices[i];
@@ -84,7 +87,7 @@ class CoinChartsConvert extends React.Component {
8487
}
8588
}
8689

87-
this.setState({_selected_cryptocurrency_price}, () => {this._handle_cryptocurrency_input_value_change(null)});
90+
this.setState({_min_date, _selected_cryptocurrency_price}, () => {this._handle_cryptocurrency_input_value_change(null)});
8891
}
8992
};
9093

@@ -127,7 +130,7 @@ class CoinChartsConvert extends React.Component {
127130
render() {
128131

129132
const { classes, selected_currency, _selected_date, coin_data, coin_id } = this.state;
130-
const { _cryptocurrency_input_value, _fiat_input_value } = this.state;
133+
const { _cryptocurrency_input_value, _fiat_input_value, _min_date } = this.state;
131134

132135
const date_format = this._get_date_format();
133136

@@ -155,6 +158,9 @@ class CoinChartsConvert extends React.Component {
155158
<KeyboardDatePicker
156159
cancelLabel={t("words.cancel")}
157160
okLabel={t("words.ok")}
161+
minDate={_min_date}
162+
maxDate={Date.now()}
163+
disableFuture={true}
158164
invalidDateMessage={t("sentences.invalid date message")}
159165
className={classes.noTopMargin}
160166
margin="normal"

src/js/utils/constants.js

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,166 @@ const CURRENCY_COUNTRIES = {
189189
ZAR: ["ZA"],
190190
};
191191

192+
const FIRST_WEEK_DAY_BY_COUNTRY = {
193+
"001": "mon",
194+
"AD": "mon",
195+
"AE": "sat",
196+
"AF": "sat",
197+
"AG": "sun",
198+
"AI": "mon",
199+
"AL": "mon",
200+
"AM": "mon",
201+
"AN": "mon",
202+
"AR": "mon",
203+
"AS": "sun",
204+
"AT": "mon",
205+
"AU": "sun",
206+
"AX": "mon",
207+
"AZ": "mon",
208+
"BA": "mon",
209+
"BD": "sun",
210+
"BE": "mon",
211+
"BG": "mon",
212+
"BH": "sat",
213+
"BM": "mon",
214+
"BN": "mon",
215+
"BR": "sun",
216+
"BS": "sun",
217+
"BT": "sun",
218+
"BW": "sun",
219+
"BY": "mon",
220+
"BZ": "sun",
221+
"CA": "sun",
222+
"CH": "mon",
223+
"CL": "mon",
224+
"CM": "mon",
225+
"CN": "sun",
226+
"CO": "sun",
227+
"CR": "mon",
228+
"CY": "mon",
229+
"CZ": "mon",
230+
"DE": "mon",
231+
"DJ": "sat",
232+
"DK": "mon",
233+
"DM": "sun",
234+
"DO": "sun",
235+
"DZ": "sat",
236+
"EC": "mon",
237+
"EE": "mon",
238+
"EG": "sat",
239+
"ES": "mon",
240+
"ET": "sun",
241+
"FI": "mon",
242+
"FJ": "mon",
243+
"FO": "mon",
244+
"FR": "mon",
245+
"GB": "mon",
246+
"GB-alt-variant": "sun",
247+
"GE": "mon",
248+
"GF": "mon",
249+
"GP": "mon",
250+
"GR": "mon",
251+
"GT": "sun",
252+
"GU": "sun",
253+
"HK": "sun",
254+
"HN": "sun",
255+
"HR": "mon",
256+
"HU": "mon",
257+
"ID": "sun",
258+
"IE": "mon",
259+
"IL": "sun",
260+
"IN": "sun",
261+
"IQ": "sat",
262+
"IR": "sat",
263+
"IS": "mon",
264+
"IT": "mon",
265+
"JM": "sun",
266+
"JO": "sat",
267+
"JP": "sun",
268+
"KE": "sun",
269+
"KG": "mon",
270+
"KH": "sun",
271+
"KR": "sun",
272+
"KW": "sat",
273+
"KZ": "mon",
274+
"LA": "sun",
275+
"LB": "mon",
276+
"LI": "mon",
277+
"LK": "mon",
278+
"LT": "mon",
279+
"LU": "mon",
280+
"LV": "mon",
281+
"LY": "sat",
282+
"MC": "mon",
283+
"MD": "mon",
284+
"ME": "mon",
285+
"MH": "sun",
286+
"MK": "mon",
287+
"MM": "sun",
288+
"MN": "mon",
289+
"MO": "sun",
290+
"MQ": "mon",
291+
"MT": "sun",
292+
"MV": "fri",
293+
"MX": "sun",
294+
"MY": "mon",
295+
"MZ": "sun",
296+
"NI": "sun",
297+
"NL": "mon",
298+
"NO": "mon",
299+
"NP": "sun",
300+
"NZ": "mon",
301+
"OM": "sat",
302+
"PA": "sun",
303+
"PE": "sun",
304+
"PH": "sun",
305+
"PK": "sun",
306+
"PL": "mon",
307+
"PR": "sun",
308+
"PT": "sun",
309+
"PY": "sun",
310+
"QA": "sat",
311+
"RE": "mon",
312+
"RO": "mon",
313+
"RS": "mon",
314+
"RU": "mon",
315+
"SA": "sun",
316+
"SD": "sat",
317+
"SE": "mon",
318+
"SG": "sun",
319+
"SI": "mon",
320+
"SK": "mon",
321+
"SM": "mon",
322+
"SV": "sun",
323+
"SY": "sat",
324+
"TH": "sun",
325+
"TJ": "mon",
326+
"TM": "mon",
327+
"TR": "mon",
328+
"TT": "sun",
329+
"TW": "sun",
330+
"UA": "mon",
331+
"UM": "sun",
332+
"US": "sun",
333+
"UY": "mon",
334+
"UZ": "mon",
335+
"VA": "mon",
336+
"VE": "sun",
337+
"VI": "sun",
338+
"VN": "mon",
339+
"WS": "sun",
340+
"XK": "mon",
341+
"YE": "sun",
342+
"ZA": "sun",
343+
"ZW": "sun"
344+
}
345+
192346
module.exports = {
193347
LOCALE_MAP: LOCALE_MAP,
194348
HISTORY: HISTORY,
195349
PAGE_ROUTES: PAGE_ROUTES,
196350
COINS: COINS,
197351
LOCALES: LOCALES,
198-
CURRENCY_COUNTRIES: CURRENCY_COUNTRIES
352+
CURRENCY_COUNTRIES: CURRENCY_COUNTRIES,
353+
FIRST_WEEK_DAY_BY_COUNTRY: FIRST_WEEK_DAY_BY_COUNTRY,
199354
};

0 commit comments

Comments
 (0)