SwiftMoment icon indicating copy to clipboard operation
SwiftMoment copied to clipboard

Subtracting months edge case - subtracts 30 days

Open phaddius opened this issue 7 years ago • 2 comments

It seems to subtract 30 days instead of 1 whole month.

Detailed Description

If the starting date is 1/30/2018, and I subtract 1 month, it becomes 12/31/2017, I would have expected 12/30/2017. If I subtract 2 months, it becomes 12/01/2017. I would have expected it to be 11/30/2017.

Your Environment

  • Version used: 0.7
  • Operating System and version: latest version of Swift, Xcode

phaddius avatar Jan 30 '18 22:01 phaddius

image

same problem the data should be 2018-02-02 16:00:00

but after moment(date, dateFormat: "YYYY-MM-DD HH:mm:ss")!

the date change to 2018-01-02 16:00:00 GMT+08:00

WingCH avatar Feb 02 '18 04:02 WingCH

i find a way can to avoid this bug use moment(year,month,day,hour,minute,second) to create , do not use dateFormat, seems can avoid the bugs

WingCH avatar Feb 02 '18 10:02 WingCH