Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3172: Add month layout
Browse files Browse the repository at this point in the history
cemalettin-work committed Sep 14, 2020
1 parent d4595d3 commit 4f1cb0d
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 4f1cb0d

Please sign in to comment.