|
| 1 | +/* eslint-disable no-tabs */ |
1 | 2 | import React from 'react'; |
2 | 3 | import PropTypes from 'prop-types'; |
3 | 4 | import styled from 'styled-components'; |
@@ -29,97 +30,95 @@ const YearComponentItem = styled.div` |
29 | 30 | `; |
30 | 31 |
|
31 | 32 | const mapMonth = [ |
32 | | - 'Jan', |
33 | | - 'Feb', |
34 | | - 'Mar', |
35 | | - 'Apr', |
36 | | - 'May', |
37 | | - 'Jun', |
38 | | - 'Jul', |
39 | | - 'Aug', |
40 | | - 'Sept', |
41 | | - 'Oct', |
42 | | - 'Nov', |
43 | | - 'Dec' |
| 33 | + 'Jan', |
| 34 | + 'Feb', |
| 35 | + 'Mar', |
| 36 | + 'Apr', |
| 37 | + 'May', |
| 38 | + 'Jun', |
| 39 | + 'Jul', |
| 40 | + 'Aug', |
| 41 | + 'Sept', |
| 42 | + 'Oct', |
| 43 | + 'Nov', |
| 44 | + 'Dec', |
44 | 45 | ]; |
45 | 46 |
|
46 | | -const handleTransformMonth = (m, t) => { |
47 | | - if (t === 'number') { |
48 | | - return m.length === 1 ? `0${m}` : m; |
49 | | - } |
50 | | - if (t === 'text') { |
51 | | - const index = m - 1; |
52 | | - return mapMonth[index]; |
53 | | - } |
| 47 | +const handleTransformMonth = (month, type) => { |
| 48 | + if (type === 'number') { |
| 49 | + return month.length === 1 ? `0${month}` : month; |
| 50 | + } |
| 51 | + const index = month - 1; |
| 52 | + return mapMonth[index]; |
54 | 53 | }; |
55 | 54 |
|
56 | | -const handleGetDate = (m, t, d, y) => { |
57 | | - const _m = handleTransformMonth(m, t); |
| 55 | +const handleGetDate = (month, type, day, year) => { |
| 56 | + const newMonth = handleTransformMonth(month, type); |
58 | 57 |
|
59 | | - if (d !== '' && m !== '') { |
60 | | - if (t === 'text') { |
61 | | - return `${_m} ${d}, ${y}`; |
62 | | - } |
63 | | - return `${_m}-${d}-${y}`; |
64 | | - } |
65 | | - if (m !== '') { |
66 | | - if (t === 'text') { |
67 | | - return `${_m}, ${y}`; |
68 | | - } |
69 | | - return `${_m}-${y}`; |
70 | | - } |
71 | | - if (d === '' && m === '') { |
72 | | - return y; |
73 | | - } |
| 58 | + if (day !== '' && month !== '') { |
| 59 | + if (type === 'text') { |
| 60 | + return `${newMonth} ${day}, ${year}`; |
| 61 | + } |
| 62 | + return `${newMonth}-${day}-${year}`; |
| 63 | + } |
| 64 | + if (month !== '') { |
| 65 | + if (type === 'text') { |
| 66 | + return `${newMonth}, ${year}`; |
| 67 | + } |
| 68 | + return `${newMonth}-${year}`; |
| 69 | + } |
| 70 | + return year; |
74 | 71 | }; |
75 | 72 |
|
76 | | -const handlePrintDate = (mounth, day, year, month_type, current) => { |
77 | | - const _date = new Date(); |
78 | | - const startDate = handleGetDate(mounth, month_type, day, year); |
| 73 | +const handlePrintDate = (mounth, day, year, monthType, current) => { |
| 74 | + const date = new Date(); |
| 75 | + const startDate = handleGetDate(mounth, monthType, day, year); |
79 | 76 |
|
80 | | - if (current) { |
81 | | - return ( |
82 | | - <> |
83 | | - <YearComponentItem className="item-year-component"> |
84 | | - {_date.getFullYear()} |
85 | | - </YearComponentItem> |
86 | | - <YearComponentItem className="item-year-component"> |
87 | | - {startDate} |
88 | | - </YearComponentItem> |
89 | | - </> |
90 | | - ); |
91 | | - } |
92 | | - return ( |
93 | | - <YearComponentItem className="item-year-component"> |
94 | | - {startDate} |
95 | | - </YearComponentItem> |
96 | | - ); |
| 77 | + if (current) { |
| 78 | + return ( |
| 79 | + <> |
| 80 | + <YearComponentItem className="item-year-component"> |
| 81 | + {date.getFullYear()} |
| 82 | + </YearComponentItem> |
| 83 | + <YearComponentItem className="item-year-component"> |
| 84 | + {startDate} |
| 85 | + </YearComponentItem> |
| 86 | + </> |
| 87 | + ); |
| 88 | + } |
| 89 | + return ( |
| 90 | + <YearComponentItem className="item-year-component"> |
| 91 | + {startDate} |
| 92 | + </YearComponentItem> |
| 93 | + ); |
97 | 94 | }; |
98 | 95 |
|
99 | | -const ContentYear = props => { |
100 | | - const { startMonth, startDay, startYear, monthType, currentYear } = props; |
| 96 | +const ContentYear = (props) => { |
| 97 | + const { |
| 98 | + startMonth, startDay, startYear, monthType, currentYear, |
| 99 | + } = props; |
101 | 100 |
|
102 | | - return ( |
103 | | - <YearComponent className="year-component"> |
104 | | - {handlePrintDate(startMonth, startDay, startYear, monthType, currentYear)} |
105 | | - </YearComponent> |
106 | | - ); |
| 101 | + return ( |
| 102 | + <YearComponent className="year-component"> |
| 103 | + {handlePrintDate(startMonth, startDay, startYear, monthType, currentYear)} |
| 104 | + </YearComponent> |
| 105 | + ); |
107 | 106 | }; |
108 | 107 |
|
109 | 108 | ContentYear.defaultProps = { |
110 | | - startMonth: '', |
111 | | - monthType: 'number', |
112 | | - startDay: '', |
113 | | - currentYear: false |
| 109 | + startMonth: '', |
| 110 | + monthType: 'number', |
| 111 | + startDay: '', |
| 112 | + currentYear: false, |
114 | 113 | }; |
115 | 114 |
|
116 | 115 | ContentYear.propTypes = { |
117 | | - startMonth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
118 | | - monthType: PropTypes.oneOf(['text', 'number']), |
119 | | - startDay: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
120 | | - startYear: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) |
121 | | - .isRequired, |
122 | | - currentYear: PropTypes.bool |
| 116 | + startMonth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
| 117 | + monthType: PropTypes.oneOf(['text', 'number']), |
| 118 | + startDay: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
| 119 | + startYear: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) |
| 120 | + .isRequired, |
| 121 | + currentYear: PropTypes.bool, |
123 | 122 | }; |
124 | 123 |
|
125 | 124 | export default ContentYear; |
0 commit comments