File tree Expand file tree Collapse file tree 1 file changed +24
-11
lines changed Expand file tree Collapse file tree 1 file changed +24
-11
lines changed Original file line number Diff line number Diff line change 1
- import PropTypes from "prop-types"
2
- import React from "react"
1
+ import moment from "moment"
3
2
4
3
const monthLayout = ( { item, dimensions } ) => {
5
- return (
6
- < >
7
- Hello { item } { dimensions }
8
- </ >
9
- )
10
- }
11
- monthLayout . propTypes = {
12
- item : PropTypes . object ,
13
- dimensions : PropTypes . object
4
+ // figure out which month
5
+ const momentDate = moment ( item . date )
6
+
7
+ // This is the [0,0] day of the month
8
+ const firstDayofFirstWeekOfTheMonth = momentDate
9
+ . startOf ( "month" )
10
+ . startOf ( "isoWeek" )
11
+
12
+ const endOfMonth = momentDate . endOf ( "month" )
13
+
14
+ const numOfWeeks = endOfMonth . diff ( firstDayofFirstWeekOfTheMonth , "weeks" ) + 1
15
+ const daysDiff = momentDate . diff ( firstDayofFirstWeekOfTheMonth , "days" )
16
+
17
+ const weekDiff = Math . floor ( daysDiff / 7 )
18
+ const weekDayDiff = daysDiff % 7
19
+
20
+ return {
21
+ xPos : ( dimensions . width * weekDayDiff ) / 7 ,
22
+ yPos : ( dimensions . height * weekDiff ) / numOfWeeks ,
23
+ width : dimensions . width / 7 ,
24
+ height : dimensions . height / numOfWeeks
25
+ }
14
26
}
27
+
15
28
export default monthLayout
You can’t perform that action at this time.
0 commit comments