Duration year

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Duration year

HilaireFernandes
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


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

bestlem
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


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

jgfoster
In reply to this post by HilaireFernandes
More precisely, 365.242199 (http://www.timeanddate.com/date/leapyear.html).

> On Nov 22, 2014, at 3:03 AM, Hilaire <[hidden email]> 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
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

NorbertHartl
In reply to this post by bestlem

> Am 23.11.2014 um 14:18 schrieb Mark Bestley <[hidden email]>:
>
> 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



cbc
Reply | Threaded
Open this post in threaded view
|

Re: Duration year

cbc
In reply to this post by HilaireFernandes
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 <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

Re: Duration year

Esteban A. Maringolo
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 <[hidden email]> 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 <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

Re: Duration year

Sean P. DeNigris
Administrator
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%29.aspx 
Cheers,
Sean
cbc
Reply | Threaded
Open this post in threaded view
|

Re: Duration year

cbc
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 <[hidden email]> 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%29.aspx



-----
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.


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

Maximiliano Taborda
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 <[hidden email]>:
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 <[hidden email]> 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%29.aspx



-----
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.



Reply | Threaded
Open this post in threaded view
|

Re: Duration year

HilaireFernandes
In reply to this post by Sean P. DeNigris
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%29.aspx 
>

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


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

jgfoster

> On Dec 3, 2014, at 12:33 PM, Hilaire <[hidden email]> 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%29.aspx 
>>
>
> 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.
Reply | Threaded
Open this post in threaded view
|

Re: Duration year

HilaireFernandes
Indeed!

Thanks

Le 04/12/2014 16:28, James Foster a écrit :

>
>> On Dec 3, 2014, at 12:33 PM, Hilaire <[hidden email]> 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%29.aspx 
>>>
>>
>> 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


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

stepharo
In reply to this post by Maximiliano Taborda
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:
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 <[hidden email]>:
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 <[hidden email]> 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%29.aspx



-----
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.




Reply | Threaded
Open this post in threaded view
|

Re: Duration year

HilaireFernandes
In reply to this post by Maximiliano Taborda
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


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

David T. Lewis
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.html

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
>

Reply | Threaded
Open this post in threaded view
|

Re: Duration year

HilaireFernandes
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.html
>
> 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


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

Chris Muller-3
In reply to this post by cbc
> 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.

Reply | Threaded
Open this post in threaded view
|

Re: Duration year

Maximiliano Taborda
In reply to this post by HilaireFernandes
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 <[hidden email]>:
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.html
>
> 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



Reply | Threaded
Open this post in threaded view
|

Re: Duration year

HilaireFernandes
In reply to this post by Chris Muller-3
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


Reply | Threaded
Open this post in threaded view
|

Re: Duration year

Sean P. DeNigris
Administrator
In reply to this post by Esteban A. Maringolo
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
12