Skip to content

Commit 4f1cb0d

Browse files
#3172: Add month layout
1 parent d4595d3 commit 4f1cb0d

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

client/src/layouts/monthLayout.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import PropTypes from "prop-types"
2-
import React from "react"
1+
import moment from "moment"
32

43
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+
}
1426
}
27+
1528
export default monthLayout

0 commit comments

Comments
 (0)