Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
Thank you all.

Re: Convert duration to years?

2017-01-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, January 15, 2017 03:43:32 Nestor via Digitalmars-d-learn wrote: > Hi, > > I would simply like to get someone's age, but I am a little lost > with time and date functions. I can already get the duration, but > after reading the documentation it's unclear to me how to convert > that into y

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 16:57:35 UTC, biozic wrote: On Sunday, 15 January 2017 at 14:20:04 UTC, Nestor wrote: On second thought, if a baby was born in march 1 of 1999 (non-leap year), in march 1 of 2000 (leap year) the age would have been one year plus one day (because of february 29).

Re: Convert duration to years?

2017-01-15 Thread biozic via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:20:04 UTC, Nestor wrote: On Sunday, 15 January 2017 at 14:04:39 UTC, Nestor wrote: ... For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and cele

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:04:39 UTC, Nestor wrote: ... For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and celebrate birthdays in february 28 of non-leap years, but marc

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 11:01:28 UTC, biozic wrote: On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correc

Re: Convert duration to years?

2017-01-15 Thread biozic via Digitalmars-d-learn
On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm)

Re: Convert duration to years?

2017-01-15 Thread ag0aep6g via Digitalmars-d-learn
On 01/15/2017 07:58 AM, Nestor wrote: I eventually came up with this, but it seems an ugly hack: import std.stdio; uint getAge(int , ubyte mm, ubyte dd) { ubyte correction; import std.datetime; SysTime t = Clock.currTime(); if (t.month < mm) correction = 1; else if (t.month == mm)

Re: Convert duration to years?

2017-01-15 Thread rikki cattermole via Digitalmars-d-learn
On 15/01/2017 9:40 PM, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) )

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) ) correction += 1; return (t.year -

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 07:25:26 UTC, rikki cattermole wrote: So I had a go at this and found I struggled looking at "magic" functions and methods. Turns out there is a much simpler answer. int getAge(int , int mm, int dd) { import std.datetime; auto t1 = cast(DateTime)SysTime(Dat

Re: Convert duration to years?

2017-01-14 Thread rikki cattermole via Digitalmars-d-learn
On 15/01/2017 4:43 PM, Nestor wrote: Hi, I would simply like to get someone's age, but I am a little lost with time and date functions. I can already get the duration, but after reading the documentation it's unclear to me how to convert that into years. See following code: import std.stdio; v

Re: Convert duration to years?

2017-01-14 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 06:23:56 UTC, Dave Chapman wrote: Does this do what you want? import std.stdio; uint getAge(int , int mm, int dd) { import std.datetime; SysTime t1 = SysTime(Date(, mm, dd)); SysTime t2 = Clock.currTime(); return( (t2.year - t1.year)); } void main()

Re: Convert duration to years?

2017-01-14 Thread Dave Chapman via Digitalmars-d-learn
On Sunday, 15 January 2017 at 03:43:32 UTC, Nestor wrote: Hi, I would simply like to get someone's age, but I am a little lost with time and date functions. I can already get the duration, but after reading the documentation it's unclear to me how to convert that into years. See following cod

Convert duration to years?

2017-01-14 Thread Nestor via Digitalmars-d-learn
Hi, I would simply like to get someone's age, but I am a little lost with time and date functions. I can already get the duration, but after reading the documentation it's unclear to me how to convert that into years. See following code: import std.stdio; void getAge(int , int mm, int d