Skip to content

Commit

Permalink
#3172: Add month layout
Browse files Browse the repository at this point in the history
  • Loading branch information
cemalettin-work committed Sep 16, 2020
1 parent 6ac69b0 commit 623281b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions client/src/layouts/monthLayout.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import PropTypes from "prop-types"
import React from "react"
import moment from "moment"

const monthLayout = ({ item, dimensions }) => {
return (
<>
Hello {item} {dimensions}
</>
)
}
monthLayout.propTypes = {
item: PropTypes.object,
dimensions: PropTypes.object
// figure out which month
const momentDate = moment(item.date)

// This is the [0,0] day of the month
const firstDayofFirstWeekOfTheMonth = momentDate
.startOf("month")
.startOf("isoWeek")

const endOfMonth = momentDate.endOf("month")

const numOfWeeks = endOfMonth.diff(firstDayofFirstWeekOfTheMonth, "weeks") + 1
const daysDiff = momentDate.diff(firstDayofFirstWeekOfTheMonth, "days")

const weekDiff = Math.floor(daysDiff / 7)
const weekDayDiff = daysDiff % 7

return {
xPos: (dimensions.width * weekDayDiff) / 7,
yPos: (dimensions.height * weekDiff) / numOfWeeks,
width: dimensions.width / 7,
height: dimensions.height / numOfWeeks
}
}

export default monthLayout

0 comments on commit 623281b

Please sign in to comment.