Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Time Zone support using localizer date math #2023

Merged
merged 39 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f7b48fe
Merge pull request #1 from intljusticemission/master
cutterbl May 6, 2019
50f71cb
Merge pull request #3 from intljusticemission/master
cutterbl May 7, 2019
681bedc
Merge pull request #4 from intljusticemission/master
cutterbl May 7, 2019
2e5a585
Merge pull request #5 from intljusticemission/master
cutterbl May 8, 2019
310b1f2
Merge pull request #6 from intljusticemission/master
cutterbl May 9, 2019
c738deb
Merge pull request #7 from intljusticemission/master
cutterbl May 9, 2019
8fb4b14
Merge remote-tracking branch 'upstream/master'
cutterbl Feb 6, 2020
90a5afb
Merge remote-tracking branch 'upstream/master'
cutterbl Feb 18, 2020
41b3333
Merge remote-tracking branch 'upstream/master'
cutterbl Sep 25, 2020
f94992c
Merge remote-tracking branch 'upstream/master'
cutterbl Aug 17, 2021
851937e
full timezone support with moment
cutterbl Aug 26, 2021
f2a9da8
chore: remove comment
cutterbl Aug 26, 2021
9207d21
chore: Add timeswitching example
cutterbl Aug 26, 2021
364cc5d
chore: continued tz efforts
cutterbl Aug 27, 2021
0ab14e6
chore(timezones): Finalize core bits for handling timezones
cutterbl Sep 8, 2021
683756c
docs: Add documentation
cutterbl Sep 8, 2021
a10ec3b
chore: CI tests don't like modern syntax
cutterbl Sep 8, 2021
ef98246
chore: Move DST calculations in to the localizers
cutterbl Sep 8, 2021
94b9934
chore: Further refine math from localizer
cutterbl Sep 9, 2021
345e709
chore: Further refine localizer date math around same date comparison
cutterbl Sep 9, 2021
eb0a156
chore: Finalize all date methods being called from localizer
cutterbl Sep 9, 2021
0d6f27d
chore: Corrections to momentLocalizer getEventRange
cutterbl Sep 9, 2021
fdaaaff
chore: Refine and use moment comparison operations
cutterbl Sep 9, 2021
f6de14e
chore: general cleanup
cutterbl Sep 9, 2021
c922e49
chore: Rebuild examples
cutterbl Sep 9, 2021
5ecee40
fix: Correct moment localizer range() method, to ensure all dates han…
cutterbl Sep 10, 2021
e8f2144
chore: Use clearer variable name
cutterbl Sep 10, 2021
c62ec6d
fix: Correct method return
cutterbl Sep 10, 2021
da6c037
fix: Correct usages of let and const for better GC and immutability
cutterbl Sep 10, 2021
6b46e43
feat: Add a new luxonLocalizer and expand documentation
cutterbl Sep 10, 2021
1374714
tests: Tested for the new luxonLocalizer
cutterbl Sep 10, 2021
389c8fa
chore: Bundle examples
cutterbl Sep 10, 2021
d290734
chore: Reset the examples script from local ip usage
cutterbl Sep 10, 2021
77de5b8
fix: startOfWeek/endOfWeek calculations
cutterbl Sep 15, 2021
490e0c8
chore: fix comment
cutterbl Sep 15, 2021
d30eee4
fix: Remove that localIp bit again
cutterbl Sep 15, 2021
72c817a
chore: General cleanup
cutterbl Sep 17, 2021
6d17ef9
fix: Correct luxon endOfWeek
cutterbl Sep 17, 2021
2865f76
fix: Correct endOfDTWeek
cutterbl Sep 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Refine and use moment comparison operations
  • Loading branch information
cutterbl committed Sep 9, 2021
commit fdaaaff6028c34c2518c506dacf7af00282b2e7f
6 changes: 3 additions & 3 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DayColumn extends React.Component {

componentDidUpdate(prevProps, prevState) {
const { getNow, isNow, localizer, date, min, max } = this.props
const getNowChanged = !localizer.eq(prevProps.getNow(), getNow(), 'minutes')
const getNowChanged = localizer.neq(prevProps.getNow(), getNow(), 'minutes')

if (prevProps.isNow !== isNow || getNowChanged) {
this.clearTimeIndicatorInterval()
Expand All @@ -63,8 +63,8 @@ class DayColumn extends React.Component {
}
} else if (
isNow &&
(!localizer.eq(prevProps.min, min, 'minutes') ||
!localizer.eq(prevProps.max, max, 'minutes'))
(localizer.neq(prevProps.min, min, 'minutes') ||
localizer.neq(prevProps.max, max, 'minutes'))
) {
this.positionTimeIndicator()
}
Expand Down
2 changes: 1 addition & 1 deletion src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MonthView extends React.Component {
UNSAFE_componentWillReceiveProps({ date }) {
const { date: propsDate, localizer } = this.props
this.setState({
needLimitMeasure: !localizer.eq(date, propsDate, 'month'),
needLimitMeasure: localizer.neq(date, propsDate, 'month'),
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export default class TimeGrid extends Component {
const { range, scrollToTime, localizer } = this.props
// When paginating, reset scroll
if (
!localizer.eq(nextProps.range[0], range[0], 'minute') ||
!localizer.eq(nextProps.scrollToTime, scrollToTime, 'minute')
localizer.neq(nextProps.range[0], range[0], 'minutes') ||
localizer.neq(nextProps.scrollToTime, scrollToTime, 'minutes')
) {
this.calculateScroll(nextProps)
}
Expand Down
59 changes: 18 additions & 41 deletions src/localizers/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ export default function(moment) {
let comparator = unit ? unit.toLowerCase() : unit
if (comparator === 'FullYear') {
comparator = 'year'
} else if (!comparator) {
comparator = undefined
}
return [moment(a), moment(b), comparator]
const dtA = comparator ? moment(a).startOf(comparator) : moment(a)
const dtB = comparator ? moment(b).startOf(comparator) : moment(b)
return [dtA, dtB, comparator]
}

function startOf(date = null, unit) {
Expand All @@ -70,64 +74,35 @@ export default function(moment) {
return moment(date).toDate()
}

// moment comparison operations *always* convert both sides to moment objects
// prior to running the comparisons
function eq(a, b, unit) {
const [dtA, dtB, comparator] = defineComparators(a, b, unit)
if (!comparator) {
return dtA.isSame(dtB)
}
const first = dtA.startOf(comparator)[comparator]()
const second = dtB.startOf(comparator)[comparator]()
return first === second
return dtA.isSame(dtB, comparator)
}

function neq(a, b, unit) {
const [dtA, dtB, comparator] = defineComparators(a, b, unit)
if (!comparator) {
return !dtA.isSame(dtB)
}
const first = dtA.startOf(comparator)[comparator]()
const second = dtB.startOf(comparator)[comparator]()
return first !== second
return !eq(a, b, unit)
}

function gt(a, b, unit) {
const [dtA, dtB, comparator] = defineComparators(a, b, unit)
if (!comparator) {
return dtA.isAfter(dtB)
}
const first = dtA.startOf(comparator)[comparator]()
const second = dtB.startOf(comparator)[comparator]()
return first > second
return dtA.isAfter(dtB, comparator)
}

function lt(a, b, unit) {
const [dtA, dtB, comparator] = defineComparators(a, b, unit)
if (!comparator) {
return dtA.isBefore(dtB)
}
const first = dtA.startOf(comparator)[comparator]()
const second = dtB.startOf(comparator)[comparator]()
return first < second
return dtA.isBefore(dtB, comparator)
}

function gte(a, b, unit) {
const [dtA, dtB, comparator] = defineComparators(a, b, unit)
if (!comparator) {
return dtA.isSameOrAfter(dtB)
}
const first = dtA.startOf(comparator)[comparator]()
const second = dtB.startOf(comparator)[comparator]()
return first >= second
return dtA.isSameOrBefore(dtB, comparator)
}

function lte(a, b, unit) {
const [dtA, dtB, comparator] = defineComparators(a, b, unit)
if (!comparator) {
return dtA.isSameOrBefore(dtB)
}
const first = dtA.startOf(comparator)[comparator]()
const second = dtB.startOf(comparator)[comparator]()
return first <= second
return dtA.isSameOrBefore(dtB, comparator)
}

function inRange(day, min, max, unit = 'day') {
Expand Down Expand Up @@ -187,8 +162,10 @@ export default function(moment) {
}

function diff(a, b, unit = 'day') {
const [dtA, dtB, comparator] = defineComparators(a, b, unit, true)
return dtB.diff(dtA, comparator)
// don't use 'defineComparators' here, as we don't want to mutate the values
const dtA = moment(a)
const dtB = moment(b)
return dtB.diff(dtA, unit === 'FullYear' ? 'year' : unit)
}

function minutes(date) {
Expand Down Expand Up @@ -298,7 +275,7 @@ export default function(moment) {

const startsBeforeEnd = startOfDay.isSameOrBefore(rEnd, 'day')
// when the event is zero duration we need to handle a bit differently
const sameMin = !startOfDay.isSame(eEnd, 'minutes') //neq(startOfDay, eEnd, 'minutes')
const sameMin = !startOfDay.isSame(eEnd, 'minutes')
const endsAfterStart = sameMin
? eEnd.isAfter(rStart, 'minutes')
: eEnd.isSameOrAfter(rStart, 'minutes')
Expand Down