andrewmcveigh / cljs-time

A clj-time inspired date library for clojurescript.
342 stars 57 forks source link

Problem using minus with months #55

Closed bago2k4 closed 8 years ago

bago2k4 commented 8 years ago

Hi, I'm working with quarters for a project of my company and i found something that may be a bug. Here are the steps to reproduce:

cljs.user=> (require '[cljs-time.core :as t])
cljs.user=> (def starting-date (t/date-time 2015 10))
#'cljs.user/starting-date
cljs.user=> starting-date
#object[Object 20151001T000000]
cljs.user=> (t/minus starting-date (t/months (* 6 3)))
#object[Object 20140401T000000]
cljs.user=> (t/minus starting-date (t/months (* 7 3)))
#object[Object 20130101T000000]

As you can see if you do 2015/10/01 minus 18 months (6 * 3) you get 2014/04/01 that is correct but if you subtract 21 months (7 * 3) you get 2013/01/01 that is incorrect, it should be 2014/01/01 or 2013/12/31 (or something like that).

Do you think this is a bug or I'm using it the wrong way?

belucid commented 8 years ago

I added a PR with a failing test for this. Here's the correct result from clj-time:

(def start (t/date-time 2015 10))
start
#object[org.joda.time.DateTime 0x53d93610 "2015-10-01T00:00:00.000Z"]
(t/minus start (t/months 21))
#object[org.joda.time.DateTime 0x79943cc6 "2014-01-01T00:00:00.000Z"]
andrewmcveigh commented 8 years ago

Hi,

This is probably a bug, though I do remember fixing something like this previously. Maybe it's a regression.

Thanks for adding the tests @belucid !

belucid commented 8 years ago

Awesome @andrewmcveigh !