# adding 1 year to the date - bug?

11 messages
Open this post in threaded view
|

## adding 1 year to the date - bug?

 Hello, just simple test: (Date year: 2019 month: 2 day: 26) + 1 year. returns: 26 February 2020 OK (Date year: 2020 month: 2 day: 26) + 1 year. returns: 25 February 2021 What? (maybe I do not understand something  about dates again) Thanks! pf
Open this post in threaded view
|

## Re: adding 1 year to the date - bug?

 In Pharo 1 year is a duration of 365 days so it does not reflect leap years. -- Pavel 2018-02-26 10:43 GMT+01:00 Petr Fischer <[hidden email]>: > Hello, just simple test: > > (Date year: 2019 month: 2 day: 26) + 1 year. > returns: 26 February 2020 > OK > > (Date year: 2020 month: 2 day: 26) + 1 year. > returns: 25 February 2021 > What? > > (maybe I do not understand something  about dates again) > > Thanks! pf >
Open this post in threaded view
|

## Re: adding 1 year to the date - bug?

 In reply to this post by Petr Fischer > Am 26.02.2018 um 10:43 schrieb Petr Fischer <[hidden email]>: > > Hello, just simple test: > > (Date year: 2019 month: 2 day: 26) + 1 year. > returns: 26 February 2020 > OK > > (Date year: 2020 month: 2 day: 26) + 1 year. > returns: 25 February 2021 > What? > > (maybe I do not understand something  about dates again) That is a conceptual problem. 1 year is a duration. As it does not know which year it is the normal 365 days. And 2020 is a leap year so has 366 days. That’s why the date is shifted. Norbert
Open this post in threaded view
|

## Re: adding 1 year to the date - bug?

 Forgot to say that this is something you can experience quite often. To me the problem is that 1 year gives a duration immediately. It should work as all units that 1 year is a unit of magnitude 1 and unit year. If you apply this to a date you could make it properly to give the date one year later. I noticed that problem when I started to use the Units package of Marcus. It works for all units except durations because these are already taken. So for me there would be two benefits changing that. NorbertAm 26.02.2018 um 10:48 schrieb Norbert Hartl <[hidden email]>:Am 26.02.2018 um 10:43 schrieb Petr Fischer <[hidden email]>:Hello, just simple test:(Date year: 2019 month: 2 day: 26) + 1 year.returns: 26 February 2020OK(Date year: 2020 month: 2 day: 26) + 1 year.returns: 25 February 2021What?(maybe I do not understand something  about dates again)That is a conceptual problem. 1 year is a duration. As it does not know which year it is the normal 365 days. And 2020 is a leap year so has 366 days. That’s why the date is shifted.Norbert
Open this post in threaded view
|

## Re: adding 1 year to the date - bug?

 +1 Doru > On Feb 26, 2018, at 10:54 AM, Norbert Hartl <[hidden email]> wrote: > > Forgot to say that this is something you can experience quite often. To me the problem is that 1 year gives a duration immediately. It should work as all units that 1 year is a unit of magnitude 1 and unit year. If you apply this to a date you could make it properly to give the date one year later. > I noticed that problem when I started to use the Units package of Marcus. It works for all units except durations because these are already taken. So for me there would be two benefits changing that. > > Norbert > > >> Am 26.02.2018 um 10:48 schrieb Norbert Hartl <[hidden email]>: >> >> >> >>> Am 26.02.2018 um 10:43 schrieb Petr Fischer <[hidden email]>: >>> >>> Hello, just simple test: >>> >>> (Date year: 2019 month: 2 day: 26) + 1 year. >>> returns: 26 February 2020 >>> OK >>> >>> (Date year: 2020 month: 2 day: 26) + 1 year. >>> returns: 25 February 2021 >>> What? >>> >>> (maybe I do not understand something  about dates again) >> >> That is a conceptual problem. 1 year is a duration. As it does not know which year it is the normal 365 days. And 2020 is a leap year so has 366 days. That’s why the date is shifted. >> >> Norbert > -- www.tudorgirba.com www.feenk.com "What we can governs what we wish."
Open this post in threaded view
|

## Re: adding 1 year to the date - bug?

 In reply to this post by Petr Fischer So "date addMonths: 12" behaves better for my needs. Thanks > Hello, just simple test: > > (Date year: 2019 month: 2 day: 26) + 1 year. > returns: 26 February 2020 > OK > > (Date year: 2020 month: 2 day: 26) + 1 year. > returns: 25 February 2021 > What? > > (maybe I do not understand something  about dates again) > > Thanks! pf >
Open this post in threaded view
|

## Re: adding 1 year to the date - bug?

 Am 26.02.18 um 11:13 schrieb Petr Fischer: > So "date addMonths: 12" behaves better for my needs. Thanks Hmm. We've had this discussion just the other day at Lunch. What is a month? Should addMonths: 1 and then subtractMonths: 1 on January 31st bring you back to January 31st? How would you implement that? I guess this is a problem that cannot be solved by a machine without additional context. Does 1 month later mean "on this day next month" or does it mean "exactly as many days in the future as the current month has days"? None of the two? Can one month later be in March when today is January 30th? It seems years and months are a bit incompatible with informatics ;-) In my opinion, there is more info needed than "x months/years later" in order to calculate the correct result. Joachim > > >> Hello, just simple test: >> >> (Date year: 2019 month: 2 day: 26) + 1 year. >> returns: 26 February 2020 >> OK >> >> (Date year: 2020 month: 2 day: 26) + 1 year. >> returns: 25 February 2021 >> What? >> >> (maybe I do not understand something  about dates again) >> >> Thanks! pf >> > -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel          mailto:[hidden email] Fliederweg 1                         http://www.objektfabrik.deD-71640 Ludwigsburg                  http://joachimtuchel.wordpress.comTelefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
Open this post in threaded view
|

## Re: adding 1 year to the date - bug?

 Administrator In reply to this post by NorbertHartl NorbertHartl wrote > Forgot to say that this is something you can experience quite often. To me > the problem is that 1 year gives a duration immediately. It should work as > all units that 1 year is a unit of magnitude 1 and unit year. If you apply > this to a date you could make it properly to give the date one year later. Yes!!! ----- Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html Cheers, Sean
Open this post in threaded view
|