I saw some discussion about Duration and year calculus in the list Given that it is impossible to determine the number of days in a year without the calendar years, should not 365.25 be used in place of 365 to minimize the error ? So it could look like: Duration class >> years: aNumber ^ self days: (aNumber * 365.25) truncated seconds: 0 Hilaire -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
On 22/11/2014 11:03, Hilaire wrote:
I saw some discussion about Duration and year calculus in the list
Given that it is impossible to determine the number of days in a year without the calendar years, should not 365.25 be used in place of 365 to minimize the error ?
So it could look like:
Duration class >> years: aNumber ^ self days: (aNumber * 365.25) truncated seconds: 0
I think it depends :) What use do you want to make of the answer. If for loan, bank or mortgage calculations then you need the days and adjustments and other info. If for tens of years it might work If to know the number of days it needs to be an integer. There is no one correct solution -- Mark
Am 23.11.2014 um 14:18 schrieb Mark Bestley <st@bestley.co.uk>:
On 22/11/2014 11:03, Hilaire wrote:
I saw some discussion about Duration and year calculus in the list
Given that it is impossible to determine the number of days in a year without the calendar years, should not 365.25 be used in place of 365 to minimize the error ?
So it could look like:
Duration class >> years: aNumber ^ self days: (aNumber * 365.25) truncated seconds: 0
I think it depends :)
What use do you want to make of the answer.
If for loan, bank or mortgage calculations then you need the days and adjustments and other info.
If for tens of years it might work
If to know the number of days it needs to be an integer.
There is no one correct solution
Would you really define such a fundamental thing after any use case? After all it is about the duration and 365.25 is more accurate. The duration doesn't make assumptions about a unit of measurement. If you the duration in days you should use aYear daysInYear Norbert
More precisely, 365.242199 (http://www.timeanddate.com/date/leapyear.html).
On Nov 22, 2014, at 3:03 AM, Hilaire <hilaire@drgeo.eu> wrote:
I saw some discussion about Duration and year calculus in the list
Given that it is impossible to determine the number of days in a year without the calendar years, should not 365.25 be used in place of 365 to minimize the error ?
So it could look like:
Duration class >> years: aNumber ^ self days: (aNumber * 365.25) truncated seconds: 0
Hilaire
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Hi. I was working on a GenericYear that was intended to be used for DateAndTime calculus - to be able to add and subtract an arbitrary number of years. The class by itself would not know the days - it is an arbitrary (generic) Year. It would only know the number of days when it is added (or subtracted) from an actual date (or timespan). The idea was that it would have a very specific and limited scope of responsibility. -cbc On Sat, Nov 22, 2014 at 3:03 AM, Hilaire <hilaire@drgeo.eu> wrote:
I saw some discussion about Duration and year calculus in the list
Given that it is impossible to determine the number of days in a year without the calendar years, should not 365.25 be used in place of 365 to minimize the error ?
So it could look like:
Duration class >> years: aNumber ^ self days: (aNumber * 365.25) truncated seconds: 0
Hilaire
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
I think we discussed this a few months ago. The problem is "unsolvable" as it is now, IMHO, because all the chronology objects are based on "offset" representations (since an epoch), instead of a "field based" representation. IMHO, the only way to have a proper "semantic" representation is to have field based date classes (like Java's Calendar object, not the best implementation though). Ej, which one of the followings is OK? '2012-02-29' asDate + 1 year "=> 2013-02-28" '2011-03-01' asDate + 1 year "=> 2012-02-29" '2011-03-01' asDate addMonths: 12 "=> 2012-03-01" Regards! El Mon Dec 01 2014 at 3:11:56 PM, Chris Cunningham <cunningham.cb@gmail.com> escribió:
Hi.
I was working on a GenericYear that was intended to be used for DateAndTime calculus - to be able to add and subtract an arbitrary number of years. The class by itself would not know the days - it is an arbitrary (generic) Year.
It would only know the number of days when it is added (or subtracted) from an actual date (or timespan). The idea was that it would have a very specific and limited scope of responsibility.
-cbc
On Sat, Nov 22, 2014 at 3:03 AM, Hilaire <hilaire@drgeo.eu> wrote:
I saw some discussion about Duration and year calculus in the list
Given that it is impossible to determine the number of days in a year without the calendar years, should not 365.25 be used in place of 365 to minimize the error ?
So it could look like:
Duration class >> years: aNumber ^ self days: (aNumber * 365.25) truncated seconds: 0
Hilaire
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Esteban A. Maringolo wrote
Ej, which one of the followings is OK? '2012-02-29' asDate + 1 year "=> 2013-02-28" '2011-03-01' asDate + 1 year "=> 2012-02-29"
One solution (just ignore the source ha ha) - http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%... ----- Cheers, Sean -- View this message in context: http://forum.world.st/Duration-year-tp4791727p4793656.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
GenericYear does this. The generic Year will take '2/29/2000' asDate + 1 year "=> 28 February 2001" In other words, we want it at the same time next year; more importantly the same month and close to what we have now. Also: '3/1/2001' asDate - 1 year "=> 1 March 2000" Still, same month - we want to be at the beginning of the month the previous year. Basically, my idea (and, more importantly, what I expect - hence my code) is that I want to pretend that we do have a field-based representation and make it work that way. except better (since there is no 2/29/2001).
Ej, which one of the followings is OK? '2011-03-01' asDate + 1 year "=> 2012-02-29"
Well, I have a bug here. That needs to be fixed. -cbc On Tue, Dec 2, 2014 at 8:34 AM, Sean P. DeNigris <sean@clipperadams.com> wrote:
Esteban A. Maringolo wrote
Ej, which one of the followings is OK? '2012-02-29' asDate + 1 year "=> 2013-02-28" '2011-03-01' asDate + 1 year "=> 2012-02-29"
One solution (just ignore the source ha ha) -
http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
----- Cheers, Sean -- View this message in context: http://forum.world.st/Duration-year-tp4791727p4793656.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Hi all. The same examples using Chaltén: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013" March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012" Hilaire, In Chaltén a year is a year so you don't need to care about of the number of days in it. Regards. Maxi 2014-12-02 16:37 GMT-03:00 Chris Cunningham <cunningham.cb@gmail.com>:
GenericYear does this. The generic Year will take '2/29/2000' asDate + 1 year "=> 28 February 2001" In other words, we want it at the same time next year; more importantly the same month and close to what we have now. Also: '3/1/2001' asDate - 1 year "=> 1 March 2000" Still, same month - we want to be at the beginning of the month the previous year.
Basically, my idea (and, more importantly, what I expect - hence my code) is that I want to pretend that we do have a field-based representation and make it work that way. except better (since there is no 2/29/2001).
Ej, which one of the followings is OK? '2011-03-01' asDate + 1 year "=> 2012-02-29"
Well, I have a bug here. That needs to be fixed.
-cbc
On Tue, Dec 2, 2014 at 8:34 AM, Sean P. DeNigris <sean@clipperadams.com> wrote:
Esteban A. Maringolo wrote
Ej, which one of the followings is OK? '2012-02-29' asDate + 1 year "=> 2013-02-28" '2011-03-01' asDate + 1 year "=> 2012-02-29"
One solution (just ignore the source ha ha) -
http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
----- Cheers, Sean -- View this message in context: http://forum.world.st/Duration-year-tp4791727p4793656.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
I love Chalten :) But you know it :) Stef Le 2/12/14 11:53, Maximiliano Taborda a écrit :
Hi all.
The same examples using Chaltén: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013" March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012"
Hilaire, In Chaltén a year is a year so you don't need to care about of the number of days in it.
Regards. Maxi
2014-12-02 16:37 GMT-03:00 Chris Cunningham <cunningham.cb@gmail.com <mailto:cunningham.cb@gmail.com>>:
GenericYear does this. The generic Year will take '2/29/2000' asDate + 1 year "=> 28 February 2001" In other words, we want it at the same time next year; more importantly the same month and close to what we have now. Also: '3/1/2001' asDate - 1 year "=> 1 March 2000" Still, same month - we want to be at the beginning of the month the previous year.
Basically, my idea (and, more importantly, what I expect - hence my code) is that I want to pretend that we do have a field-based representation and make it work that way. except better (since there is no 2/29/2001).
> Ej, which one of the followings is OK? > '2011-03-01' asDate + 1 year "=> 2012-02-29"
Well, I have a bug here. That needs to be fixed.
-cbc
On Tue, Dec 2, 2014 at 8:34 AM, Sean P. DeNigris <sean@clipperadams.com <mailto:sean@clipperadams.com>> wrote:
Esteban A. Maringolo wrote > Ej, which one of the followings is OK? > '2012-02-29' asDate + 1 year "=> 2013-02-28" > '2011-03-01' asDate + 1 year "=> 2012-02-29"
One solution (just ignore the source ha ha) - http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
----- Cheers, Sean -- View this message in context: http://forum.world.st/Duration-year-tp4791727p4793656.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Hi, What is Chaltén please? Hilaire Le 02/12/2014 20:53, Maximiliano Taborda a écrit :
Hi all.
The same examples using Chaltén: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013" March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012"
Hilaire, In Chaltén a year is a year so you don't need to care about of the number of days in it.
Regards. Maxi
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
On Sun, Dec 07, 2014 at 09:30:06AM +0100, Hilaire wrote:
Hi,
What is Chalt??n please?
http://lists.squeakfoundation.org/pipermail/squeak-dev/2014-April/177938.htm... https://github.com/mtaborda/chalten
Hilaire
Le 02/12/2014 20:53, Maximiliano Taborda a ??crit :
Hi all.
The same examples using Chalt??n: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013" March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012"
Hilaire, In Chalt??n a year is a year so you don't need to care about of the number of days in it.
Regards. Maxi
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Thanks. Looks interesting. Does anyone use it in production? Hilaire Le 07/12/2014 18:36, David T. Lewis a écrit :
On Sun, Dec 07, 2014 at 09:30:06AM +0100, Hilaire wrote:
Hi,
What is Chalt??n please?
http://lists.squeakfoundation.org/pipermail/squeak-dev/2014-April/177938.htm...
https://github.com/mtaborda/chalten
Hilaire
Le 02/12/2014 20:53, Maximiliano Taborda a ??crit :
Hi all.
The same examples using Chalt??n: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013" March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012"
Hilaire, In Chalt??n a year is a year so you don't need to care about of the number of days in it.
Regards. Maxi
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Yes Hilaire, it is used in production. Mainly in systems related to the financial domain. Regards, Maxi 2014-12-07 16:51 GMT-03:00 Hilaire <hilaire@drgeo.eu>:
Thanks. Looks interesting. Does anyone use it in production?
Hilaire
Le 07/12/2014 18:36, David T. Lewis a écrit :
On Sun, Dec 07, 2014 at 09:30:06AM +0100, Hilaire wrote:
Hi,
What is Chalt??n please?
http://lists.squeakfoundation.org/pipermail/squeak-dev/2014-April/177938.htm...
https://github.com/mtaborda/chalten
Hilaire
Le 02/12/2014 20:53, Maximiliano Taborda a ??crit :
Hi all.
The same examples using Chalt??n: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013" March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012"
Hilaire, In Chalt??n a year is a year so you don't need to care about
of
the number of days in it.
Regards. Maxi
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Maximiliano Taborda wrote
Hi all.
The same examples using Chaltén: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013"
This I don't get. Why would <February 28th> + 1 day + 1 year ever not be March 1st? ~75% of the time it would be, but ~25% it would be a day less?
March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012"
Hilaire, In Chaltén a year is a year so you don't need to care about of the number of days in it.
Regards. Maxi
2014-12-02 16:37 GMT-03:00 Chris Cunningham <
cunningham.cb@
>:
GenericYear does this. The generic Year will take '2/29/2000' asDate + 1 year "=> 28 February 2001" In other words, we want it at the same time next year; more importantly the same month and close to what we have now. Also: '3/1/2001' asDate - 1 year "=> 1 March 2000" Still, same month - we want to be at the beginning of the month the previous year.
Basically, my idea (and, more importantly, what I expect - hence my code) is that I want to pretend that we do have a field-based representation and make it work that way. except better (since there is no 2/29/2001).
Ej, which one of the followings is OK? '2011-03-01' asDate + 1 year "=> 2012-02-29"
Well, I have a bug here. That needs to be fixed.
-cbc
On Tue, Dec 2, 2014 at 8:34 AM, Sean P. DeNigris <
sean@
>
wrote:
Esteban A. Maringolo wrote
Ej, which one of the followings is OK? '2012-02-29' asDate + 1 year "=> 2013-02-28" '2011-03-01' asDate + 1 year "=> 2012-02-29"
One solution (just ignore the source ha ha) -
http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
----- Cheers, Sean -- View this message in context: http://forum.world.st/Duration-year-tp4791727p4793656.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
-- View this message in context: http://forum.world.st/Duration-year-tp4791727p4813662.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Hi Richard, In Chalten, if you don't talk of a year in particular, February 28th + 1 day always returns March 1st. This is because Chalten asumes the structure of a non-leap year for calculate this. But, if you know the year, like in my previous example (the year 2012) then February 28th, 2012 + 1 day returns February 29th, 2012. Then, as 2012 is a leap year and I want to add 1 year to the last day of February of year 2012 (the 29th), then the result is the last day of February of 2013 (the 28th). Note that in one case we are talking about days of month (i.e. February 28th) and in the other case we are talking about dates (i.e. February 28th, 2012). Is it more clear now? By the way, reading your mail I found a little bug in Chalten. I will fix it in a couple of days. Thanks! Kind regards, Maxi 2015-03-20 14:47 GMT-03:00 Richard Sargent < richard.sargent@gemtalksystems.com>:
Maximiliano Taborda wrote
Hi all.
The same examples using Chaltén: February twentyninth, 2012 next: 1 yearMeasure. "=> February 28th, 2013"
This I don't get. Why would <February 28th> + 1 day + 1 year ever not be March 1st? ~75% of the time it would be, but ~25% it would be a day less?
March first, 2011 next: 1 yearMeasure. "=> March 1st, 2012" March first, 2011 next: 12 monthsMeasure. "=> March 1st, 2012"
Hilaire, In Chaltén a year is a year so you don't need to care about of the number of days in it.
Regards. Maxi
2014-12-02 16:37 GMT-03:00 Chris Cunningham <
cunningham.cb@
>:
GenericYear does this. The generic Year will take '2/29/2000' asDate + 1 year "=> 28 February 2001" In other words, we want it at the same time next year; more importantly the same month and close to what we have now. Also: '3/1/2001' asDate - 1 year "=> 1 March 2000" Still, same month - we want to be at the beginning of the month the previous year.
Basically, my idea (and, more importantly, what I expect - hence my code) is that I want to pretend that we do have a field-based representation and make it work that way. except better (since there is no 2/29/2001).
Ej, which one of the followings is OK? '2011-03-01' asDate + 1 year "=> 2012-02-29"
Well, I have a bug here. That needs to be fixed.
-cbc
On Tue, Dec 2, 2014 at 8:34 AM, Sean P. DeNigris <
sean@
>
wrote:
Esteban A. Maringolo wrote
Ej, which one of the followings is OK? '2012-02-29' asDate + 1 year "=> 2013-02-28" '2011-03-01' asDate + 1 year "=> 2012-02-29"
One solution (just ignore the source ha ha) -
http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
----- Cheers, Sean -- View this message in context: http://forum.world.st/Duration-year-tp4791727p4793656.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
-- View this message in context: http://forum.world.st/Duration-year-tp4791727p4813662.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Le 02/12/2014 17:34, Sean P. DeNigris a écrit :
One solution (just ignore the source ha ha) - http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
Something like ? Date>>addYears: integer ^ Date year: self year + integer month: self monthIndex day: ((self dayOfMonth = 29 and: [(Year isLeapYear: self year + integer) not and: [Year isLeapYear: self year]]) ifTrue: [ 28 ] ifFalse: [ self dayOfMonth]) -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
On Dec 3, 2014, at 12:33 PM, Hilaire <hilaire@drgeo.eu> wrote:
Le 02/12/2014 17:34, Sean P. DeNigris a écrit :
One solution (just ignore the source ha ha) - http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
Something like ?
Date>>addYears: integer ^ Date year: self year + integer month: self monthIndex day: ((self dayOfMonth = 29 and: [(Year isLeapYear: self year + integer) not and: [Year isLeapYear: self year]]) ifTrue: [ 28 ] ifFalse: [ self dayOfMonth])
From a brief read of the code it looks like the day formula should have a check for monthIndex == 2. Otherwise, January 29 can turn in to January 28.
Indeed! Thanks Le 04/12/2014 16:28, James Foster a écrit :
On Dec 3, 2014, at 12:33 PM, Hilaire <hilaire@drgeo.eu> wrote:
Le 02/12/2014 17:34, Sean P. DeNigris a écrit :
One solution (just ignore the source ha ha) - http://msdn.microsoft.com/en-us/library/system.datetime.addyears%28v=vs.110%...
Something like ?
Date>>addYears: integer ^ Date year: self year + integer month: self monthIndex day: ((self dayOfMonth = 29 and: [(Year isLeapYear: self year + integer) not and: [Year isLeapYear: self year]]) ifTrue: [ 28 ] ifFalse: [ self dayOfMonth])
From a brief read of the code it looks like the day formula should have a check for monthIndex == 2. Otherwise, January 29 can turn in to January 28.
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Esteban A. Maringolo wrote
The problem is "unsolvable" as it is now, IMHO, because all the chronology objects are based on "offset" representations (since an epoch)
The more I work with Dates, the more I feel that, unless we do something "correct" like Chalten or GenericYear, years should be totally removed from Duration. Maybe for Pharo 5.0? ----- Cheers, Sean -- View this message in context: http://forum.world.st/Duration-year-tp4791727p4813313.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Le 19/03/2015 19:03, Sean P. DeNigris a écrit :
Esteban A. Maringolo wrote
The problem is "unsolvable" as it is now, IMHO, because all the chronology objects are based on "offset" representations (since an epoch) The more I work with Dates, the more I feel that, unless we do something "correct" like Chalten or GenericYear, years should be totally removed from Duration. Maybe for Pharo 5.0?
Agreed we can improve the situation. Hilaire -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
I was working on a GenericYear that was intended to be used for DateAndTime calculus - to be able to add and subtract an arbitrary number of years. The class by itself would not know the days - it is an arbitrary (generic) Year.
It would only know the number of days when it is added (or subtracted) from an actual date (or timespan). The idea was that it would have a very specific and limited scope of responsibility.
I liked it. Hopefully a few loose ends can be fixed up so it can be put into trunk.
Le 09/12/2014 02:15, Chris Muller a écrit :
I was working on a GenericYear that was intended to be used for DateAndTime calculus - to be able to add and subtract an arbitrary number of years. The class by itself would not know the days - it is an arbitrary (generic) Year.
It would only know the number of days when it is added (or subtracted) from an actual date (or timespan). The idea was that it would have a very specific and limited scope of responsibility.
I liked it. Hopefully a few loose ends can be fixed up so it can be put into trunk.
This one should be better addYears: integer ^ Date year: self year + integer month: self monthIndex day: ((self monthIndex = 2 and: [self dayOfMonth = 29 and: [(Year isLeapYear: self year) and: [(Year isLeapYear: self year + integer) not ]]]) ifTrue: [ 28 ] ifFalse: [ self dayOfMonth]) -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
participants (12)
-
Chris Cunningham -
Chris Muller -
David T. Lewis -
Esteban A. Maringolo -
Hilaire -
James Foster -
Mark Bestley -
Maximiliano Taborda -
Norbert Hartl -
Richard Sargent -
Sean P. DeNigris -
stepharo