Date utils Month subtraction fails on the 31st of Jan 2022
See original GitHub issueWhat happened?
import { date } from 'quasar'
const monthsToBeRetrieved = 3
const today = Date.now()
for (let i = this.monthsBack; i < this.monthsBack + monthsToBeRetrieved; i++) {
const month = date.subtractFromDate(today, { months: i })
const formatMonth = date.formatDate(month, 'YYYY-MM')
Today, this loop creates the dates January, December AND DECEMBER As if subtracting a month subtracts 30 days, instead of the calendar month length.
What did you expect to happen?
I expected the date.subtractFromDate to subtract a month accurately, as Momentjs does it because that’s what’s said in the documentation:
… and remember that you don’t need solutions like Momentjs which add hundreds of minified KB to your bundle.
Reproduction URL
…
How to reproduce?
Copy paste For loop above, run code on 31 January or use Timekeeper to set date.
Flavour
Quasar CLI (@quasar/cli | @quasar/app)
Areas
Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app), Plugins (quasar), Quasar Extras (@quasar/extras)
Platforms/Browsers
Firefox, Chrome, Safari, Microsoft Edge, iOS, Android, Electron, Other
Quasar info output
Operating System - Darwin(21.2.0) - darwin/x64
NodeJs - 14.18.2
Global packages
NPM - 6.14.15
yarn - 1.22.17
@quasar/cli - 1.2.2
@quasar/icongenie - Not installed
cordova - Not installed
Important local packages
quasar - 2.4.12 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
@quasar/app - 3.2.9 -- Quasar Framework local CLI
@quasar/extras - 1.12.4 -- Quasar Framework fonts, icons and animations
eslint-plugin-quasar - Not installed
vue - 3.2.24 -- The progressive JavaScript framework for buiding modern web UI.
vue-router - 4.0.12
vuex - 4.0.2 -- state management for Vue.js
electron - Not installed
electron-packager - Not installed
electron-builder - Not installed
@babel/core - 7.16.0 -- Babel compiler core.
webpack - 5.65.0 -- Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
webpack-dev-server - 4.7.3 -- Serves a webpack app. Updates the browser on changes.
workbox-webpack-plugin - Not installed
register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
typescript - 4.5.4 -- TypeScript is a language for application scale JavaScript development
@capacitor/core - Not installed
@capacitor/cli - Not installed
@capacitor/android - Not installed
@capacitor/ios - Not installed
Quasar App Extensions
@quasar/quasar-app-extension-testing - 2.0.2 -- A Quasar App Extension for managing Test Harnesses
@quasar/quasar-app-extension-testing-unit-jest - 3.0.0-alpha.7 -- A Quasar App Extension for running Jest tests
Relevant log output
...
month 0 Mon Jan 31 2022 10:43:52 GMT+0200 (South Africa Standard Time)
...?394a:78 month 1 Fri Dec 31 2021 10:43:52 GMT+0200 (South Africa Standard Time)
...?394a:78 month 2 Wed Dec 01 2021 10:43:52 GMT+0200 (South Africa Standard Time)
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Return datetime object of previous month - python
2. I am confused with the param month and months in dateutil. Subtract with param month doesn't work but months works In [23]:...
Read more >Date (Java Platform SE 8 ) - Oracle Help Center
If the date was October 31, for example, and the month is set to June, then the new date will be treated as...
Read more >SQL date format Overview; DateDiff SQL function, DateAdd ...
In the query, we're passing integer value that consists of year, 2008; month, 12 and the 7 th day. 1. 2. 3. SELECT...
Read more >Java Date and Calendar examples - Mkyong.com
This tutorial shows you how to work with java.util. ... sdf.parse(dateInString); System.out.println(date); //Tue Aug 31 10:20:56 SGT 1982.
Read more >Add to or subtract from date and time values - Microsoft Support
Displays a date that is a month after 31-Jan-04, and since 2004 is a leap year, the expression will evaluate to 29-Feb-04. =DateAdd("q",...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fix will be available in Quasar v2.5.0
Hi @AlphaJuliettOmega! 👋
It looks like you provided an invalid or unsupported reproduction URL. Do not use any service other than Codepen, jsFiddle, Codesandbox, and GitHub. Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc. Please edit your original post above and provide a valid reproduction URL as explained.
Without a proper reproduction, your issue will have to get closed.
Thank you for your collaboration. 👏