Skip to content

Commit faf9b98

Browse files
authored
Merge pull request #194 from Seluj78/FIX_birthdate
format the birthdate
2 parents 1e15511 + ccdf441 commit faf9b98

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

frontend/src/pages/onboarding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from "react";
22
import { useHistory } from "react-router-dom";
3-
import { getRefreshToken, date2Html, apiCall, logOut } from "../utils";
3+
import { getRefreshToken, date2Html, apiCall, logOut, date2string } from "../utils";
44
import Loading from "./../components/loading"
55

66
/*
@@ -86,7 +86,7 @@ const Meta = (form, setForm, key) => (
8686
</div>
8787
<div className="field">
8888
<div className="control">
89-
<input className="input" type="date" value={date2Html(form.birthdate) || ""} onChange={e => setForm('birthdate', new Date(e.target.value).valueOf())} />
89+
<input className="input" type="date" value={date2Html(form.birthdate) || ""} onChange={e => setForm('birthdate', date2string(e.target.value))} />
9090
</div>
9191
</div>
9292
</div>

frontend/src/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ const date2Html = d => {
1010
return `${year}-${month}-${date}`;
1111
}
1212

13+
const date2string = d => {
14+
const t = new Date(d);
15+
const date = ('0' + t.getDate()).slice(-2);
16+
const month = ('0' + (t.getMonth() + 1)).slice(-2);
17+
const year = t.getFullYear();
18+
return `${date}/${month}/${year}`;
19+
}
20+
1321
const delete_refresh = async () => {
1422
const token = getRefreshToken();
1523
const options = {
@@ -137,5 +145,6 @@ export {
137145
date2Html,
138146
discard,
139147
delete_refresh,
140-
logOut
148+
logOut,
149+
date2string
141150
}

0 commit comments

Comments
 (0)