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

Extend Duration documentation to document different behaviour when created out of factory methods #1627

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
47 changes: 46 additions & 1 deletion src/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,11 @@ export default class Duration {

/**
* Get the years.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
Comment on lines +868 to +869
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is factually incorrect. Duration.fromObject({ years: 2 }).years is 2, not 0.
I am not sure what you're referring to by "correct difference in years" here.

*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @type {number}
*/
get years() {
Expand All @@ -872,6 +877,11 @@ export default class Duration {

/**
* Get the quarters.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @type {number}
*/
get quarters() {
Expand All @@ -880,6 +890,11 @@ export default class Duration {

/**
* Get the months.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @type {number}
*/
get months() {
Expand All @@ -888,6 +903,11 @@ export default class Duration {

/**
* Get the weeks
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @type {number}
*/
get weeks() {
Expand All @@ -896,6 +916,11 @@ export default class Duration {

/**
* Get the days.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @type {number}
*/
get days() {
Expand All @@ -904,6 +929,11 @@ export default class Duration {

/**
* Get the hours.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @type {number}
*/
get hours() {
Expand All @@ -912,6 +942,11 @@ export default class Duration {

/**
* Get the minutes.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @type {number}
*/
get minutes() {
Expand All @@ -920,6 +955,11 @@ export default class Duration {

/**
* Get the seconds.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @return {number}
*/
get seconds() {
Expand All @@ -928,6 +968,11 @@ export default class Duration {

/**
* Get the milliseconds.
*
* Note: Durations created out of Duration.from* (e.g. fromObject) factories will always yield 0.
* This will give you the correct difference in years, if the Duration was created out of a diff operation.
*
* More information: https://moment.github.io/luxon/#/math?id=duration-math
* @return {number}
*/
get milliseconds() {
Expand Down Expand Up @@ -987,4 +1032,4 @@ export default class Duration {
}
return true;
}
}
}