Skip to content

Commit

Permalink
fix(agenda): fixes for firstDay prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tautvilas committed May 18, 2017
1 parent ac63b76 commit 121ec11
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions example/src/screens/agenda.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class AgendaScreen extends Component {
<Agenda
items={this.state.items}
loadItemsForMonth={this.loadItems.bind(this)}
firstDay={1}
selected={'2012-05-16'}
renderItem={this.renderItem.bind(this)}
renderEmptyDate={this.renderEmptyDate.bind(this)}
Expand Down
2 changes: 2 additions & 0 deletions example/src/screens/calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default class CalendarsScreen extends Component {
style={styles.calendar}
current={'2012-05-16'}
minDate={'2012-05-10'}
maxDate={'2012-05-29'}
firstDay={1}
selected={['2012-05-24']}
markedDates={{'2012-05-24': [true], '2012-05-25': [true]}}
hideArrows={true}
Expand Down
2 changes: 1 addition & 1 deletion src/agenda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class AgendaView extends Component {
}

render() {
const weekDaysNames = XDate.locales[XDate.defaultLocale].dayNamesShort;
const weekDaysNames = dateutils.weekDayNames(this.props.firstDay);
const maxCalHeight = this.screenHeight + 20;
const calendarStyle = [this.styles.calendar, {height: this.state.openAnimation.interpolate({
inputRange: [0, 1],
Expand Down
2 changes: 1 addition & 1 deletion src/calendar-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CalendarList extends Component {
const diffMonths = Math.round(this.state.openDate.clone().setDate(1).diffMonths(day.clone().setDate(1)));
let scrollAmount = (calendarHeight * this.pastScrollRange) + (diffMonths * calendarHeight) + (offset || 0);
let week = 0;
const days = dateutils.page(day);
const days = dateutils.page(day, this.props.firstDay);
for (let i = 0; i < days.length; i++) {
week = Math.floor(i / 7);
if (dateutils.sameDate(days[i], day)) {
Expand Down
8 changes: 2 additions & 6 deletions src/calendar/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
TouchableOpacity,
Image
} from 'react-native';
import XDate from 'xdate';
import styleConstructor from './style';
import {weekDayNames} from '../../dateutils';

class CalendarHeader extends Component {
constructor(props) {
Expand Down Expand Up @@ -38,11 +38,7 @@ class CalendarHeader extends Component {
render() {
let leftArrow = (<View/>);
let rightArrow = (<View/>);
let weekDaysNames = XDate.locales[XDate.defaultLocale].dayNamesShort;
const dayShift = this.props.firstDay % 7;
if (dayShift) {
weekDaysNames = weekDaysNames.slice(dayShift).concat(weekDaysNames.slice(0, dayShift));
}
let weekDaysNames = weekDayNames(this.props.firstDay);
if (!this.props.hideArrows) {
leftArrow = (
<TouchableOpacity onPress={this.substractMonth} style={this.style.arrow}>
Expand Down
10 changes: 10 additions & 0 deletions src/dateutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ function month(xd) {
return fromTo(firstDay, lastDay);
}

function weekDayNames(firstDayOfWeek = 0) {
let weekDaysNames = XDate.locales[XDate.defaultLocale].dayNamesShort;
const dayShift = firstDayOfWeek % 7;
if (dayShift) {
weekDaysNames = weekDaysNames.slice(dayShift).concat(weekDaysNames.slice(0, dayShift));
}
return weekDaysNames;
}

function page(xd, firstDayOfWeek) {
var days = month(xd), before = [], after = [];

Expand Down Expand Up @@ -71,6 +80,7 @@ function page(xd, firstDayOfWeek) {
}

module.exports = {
weekDayNames,
sameMonth,
sameDate,
month,
Expand Down

0 comments on commit 121ec11

Please sign in to comment.