Skip to content

Commit

Permalink
Use weekStart/workWeekStart props, not localizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mltucker committed Dec 4, 2018
1 parent 3196138 commit 97962b2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 23 deletions.
19 changes: 18 additions & 1 deletion lib/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ var Calendar = (function(_React$Component) {
_0 = _props.components,
_1 = _props.formats,
_2 = _props.messages,
weekStart = _props.weekStart,
workWeekStart = _props.workWeekStart,
props = _objectWithoutProperties(_props, [
'view',
'toolbar',
Expand All @@ -323,6 +325,8 @@ var Calendar = (function(_React$Component) {
'components',
'formats',
'messages',
'weekStart',
'workWeekStart',
])

current = current || getNow()
Expand All @@ -336,7 +340,12 @@ var Calendar = (function(_React$Component) {
viewNames = _state$context.viewNames

var CalToolbar = components.toolbar || _Toolbar2.default
var label = View.title(current, { localizer: localizer, length: length })
var label = View.title(current, {
localizer: localizer,
length: length,
weekStart: weekStart,
workWeekStart: workWeekStart,
})

return _react2.default.createElement(
'div',
Expand Down Expand Up @@ -372,6 +381,8 @@ var Calendar = (function(_React$Component) {
getNow: getNow,
length: length,
localizer: localizer,
weekStart: weekStart,
workWeekStart: workWeekStart,
getters: getters,
components: components,
accessors: accessors,
Expand All @@ -395,6 +406,12 @@ var Calendar = (function(_React$Component) {
Calendar.propTypes = {
localizer: _propTypes2.default.object.isRequired,

// When the week starts, 0 or 1.
weekStart: _propTypes2.default.number,

// When the work week starts, 0 or 1.
workWeekStart: _propTypes2.default.number,

/**
* Props passed to main calendar `<div>`.
*
Expand Down
7 changes: 3 additions & 4 deletions lib/Week.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ Week.navigate = function(date, action) {
}

Week.range = function(date, _ref) {
var localizer = _ref.localizer
var weekStart = _ref.weekStart

var firstOfWeek = localizer.startOfWeek()
var start = _dates2.default.startOf(date, 'week', firstOfWeek)
var end = _dates2.default.endOf(date, 'week', firstOfWeek)
var start = _dates2.default.startOf(date, 'week', weekStart)
var end = _dates2.default.endOf(date, 'week', weekStart)

return _dates2.default.range(start, end)
}
Expand Down
22 changes: 15 additions & 7 deletions lib/WorkWeek.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var _react = require('react')

var _react2 = _interopRequireDefault(_react)

var _dates = require('./utils/dates')

var _dates2 = _interopRequireDefault(_dates)

var _Week = require('./Week')

var _Week2 = _interopRequireDefault(_Week)
Expand Down Expand Up @@ -84,10 +88,13 @@ function _inherits(subClass, superClass) {
: (subClass.__proto__ = superClass)
}

function workWeekRange(date, options) {
return _Week2.default.range(date, options).filter(function(d) {
return [6, 0].indexOf(d.getDay()) === -1
})
function workWeekRange(date, _ref) {
var workWeekStart = _ref.workWeekStart

var start = _dates2.default.startOf(date, 'week', workWeekStart)
var end = _dates2.default.endOf(date, 'week', workWeekStart)

return _dates2.default.range(start, end).slice(0, 5)
}

var WorkWeek = (function(_React$Component) {
Expand Down Expand Up @@ -127,10 +134,11 @@ WorkWeek.range = workWeekRange

WorkWeek.navigate = _Week2.default.navigate

WorkWeek.title = function(date, _ref) {
var localizer = _ref.localizer
WorkWeek.title = function(date, _ref2) {
var localizer = _ref2.localizer,
workWeekStart = _ref2.workWeekStart

var _workWeekRange = workWeekRange(date, { localizer: localizer }),
var _workWeekRange = workWeekRange(date, { workWeekStart: workWeekStart }),
start = _workWeekRange[0],
rest = _workWeekRange.slice(1)

Expand Down
17 changes: 16 additions & 1 deletion src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class Calendar extends React.Component {
static propTypes = {
localizer: PropTypes.object.isRequired,

// When the week starts, 0 or 1.
weekStart: PropTypes.number,

// When the work week starts, 0 or 1.
workWeekStart: PropTypes.number,

/**
* Props passed to main calendar `<div>`.
*
Expand Down Expand Up @@ -833,6 +839,8 @@ class Calendar extends React.Component {
components: _0,
formats: _1,
messages: _2,
weekStart,
workWeekStart,
...props
} = this.props

Expand All @@ -848,7 +856,12 @@ class Calendar extends React.Component {
} = this.state.context

let CalToolbar = components.toolbar || Toolbar
const label = View.title(current, { localizer, length })
const label = View.title(current, {
localizer,
length,
weekStart,
workWeekStart,
})

return (
<div
Expand Down Expand Up @@ -876,6 +889,8 @@ class Calendar extends React.Component {
getNow={getNow}
length={length}
localizer={localizer}
weekStart={weekStart}
workWeekStart={workWeekStart}
getters={getters}
components={components}
accessors={accessors}
Expand Down
7 changes: 3 additions & 4 deletions src/Week.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ Week.navigate = (date, action) => {
}
}

Week.range = (date, { localizer }) => {
let firstOfWeek = localizer.startOfWeek()
let start = dates.startOf(date, 'week', firstOfWeek)
let end = dates.endOf(date, 'week', firstOfWeek)
Week.range = (date, { weekStart }) => {
let start = dates.startOf(date, 'week', weekStart)
let end = dates.endOf(date, 'week', weekStart)

return dates.range(start, end)
}
Expand Down
14 changes: 8 additions & 6 deletions src/WorkWeek.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import PropTypes from 'prop-types'
import React from 'react'
import dates from './utils/dates'

import Week from './Week'
import TimeGrid from './TimeGrid'

function workWeekRange(date, options) {
return Week.range(date, options).filter(
d => [6, 0].indexOf(d.getDay()) === -1
)
function workWeekRange(date, { workWeekStart }) {
let start = dates.startOf(date, 'week', workWeekStart)
let end = dates.endOf(date, 'week', workWeekStart)

return dates.range(start, end).slice(0, 5)
}

class WorkWeek extends React.Component {
Expand All @@ -29,8 +31,8 @@ WorkWeek.range = workWeekRange

WorkWeek.navigate = Week.navigate

WorkWeek.title = (date, { localizer }) => {
let [start, ...rest] = workWeekRange(date, { localizer })
WorkWeek.title = (date, { localizer, workWeekStart }) => {
let [start, ...rest] = workWeekRange(date, { workWeekStart })

return localizer.format({ start, end: rest.pop() }, 'dayRangeHeaderFormat')
}
Expand Down

0 comments on commit 97962b2

Please sign in to comment.