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

"By" Iterator is not returning the last date given a range #5979

Open
adrianescat opened this issue Mar 3, 2022 · 0 comments
Open

"By" Iterator is not returning the last date given a range #5979

adrianescat opened this issue Mar 3, 2022 · 0 comments

Comments

@adrianescat
Copy link

I have two dates

start

> start.toString()
'Tue Dec 14 2021 08:57:13 GMT-0300 (Argentina Standard Time)'

end

> end.toString()
'Fri Dec 17 2021 07:58:05 GMT-0300 (Argentina Standard Time)'

If I want to create a range, I get this:

Screen Shot 2022-03-03 at 13 58 01

So the range seems right, I have the range from Tue Dec 14 2021 to Fri Dec 17 2021

Ok, so I want an array of all the dates including the start, the end and the dates in between.

Using the .by operator, I'm getting only 3 dates, the last date is not being included there:

Screen Shot 2022-03-03 at 14 01 33

More visible here:

> moment.range(moment(start), moment(end)).contains(moment(end))
true

> Array.from(moment.range(moment(start), moment(end)).by('day')).map(x => x.format('MM-DD-YYYY'))
(3) ['12-14-2021', '12-15-2021', '12-16-2021']

// with excludeEnd: false
> Array.from(moment.range(moment(start), moment(end)).by('day', { excludeEnd: false })).map(x => x.format('MM-DD-YYYY'))
(3) ['12-14-2021', '12-15-2021', '12-16-2021']

// with excludeEnd: true
> Array.from(moment.range(moment(start), moment(end)).by('day', { excludeEnd: true })).map(x => x.format('MM-DD-YYYY'))
(2) ['12-14-2021', '12-15-2021']

To Reproduce
Steps to reproduce the behavior above.

Expected behavior
I need to get the 4 dates

> Array.from(moment.range(moment(start), moment(end)).by('day')).map(x => x.format('MM-DD-YYYY'))
(3) ['12-14-2021', '12-15-2021', '12-16-2021', '12-17-2021']

Screenshots
above

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • Version: 98.0.4758.109 (Official Build) (x86_64)

Moment-specific environment

  • The time zone setting of the machine the code is running on
  • The time and date at which the code was run
  • Other libraries in use (TypeScript, Immutable.js, etc)

GMT-0300 (Argentina Standard Time)
03/03/2022
Typescript and Flow

Please run the following code in your environment and include the output:

console.log((new Date()).toString())
console.log((new Date()).toLocaleString())
console.log((new Date()).getTimezoneOffset())
console.log(navigator.userAgent)
console.log(moment.version)
Thu Mar 03 2022 14:18:30 GMT-0300 (Argentina Standard Time)
3/3/2022, 2:18:30 PM
180
Uncaught ReferenceError: navigator is not defined

in package.json

"moment": "~2.29.1",
"moment-range": "~4.0.2",

Additional context
I'm running the code in vscode version 1.64.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant