Re: Subtraction Broken?
> Perhaps I'm just approaching this all wrong. I'm just looking for a simple way to compute some ones age today. What you want is to normalize the values of a duration relative to some fixed point in time. I agree this is something that we need to do. Patches are welcome. :) So if I read this correctly the answer is at this time what I'm after is not possible with DateTime directly. But, what I request is something you all desire and hope to have working when someone has the time. I actually wouldn't mind taking a look to see if I could contribute but at this point if: 1968-06-28 2003-08-17 Years:0 Months:0 Days:2 Delta Months:0 Delta Days:12833 is viewed as correct in representing the duration between those two dates I feel I'm missing a little to much to grasp some of the basics to contribute. I really don't see what the years months days methods are all about and if the delta's are simply just supposed to all add up to the duration then I can make since of the Delta's but it seems like I should have some methods representing the deltas in other forms that would also include years. Do you have some other design specs for the DateTime::Duration module that might help me to understand the above output better. However if on the other hand some part of the output above although perhaps correct not exactly what is intended or just stubs for what is desired then if I new what was intended/desired I probably could take a look and see if the effort to produce what I desire from DateTime is worth it. If years really should produce 35 and simply isn't because that method is a stub I would be happy to see what I can produce.
Re: Subtraction Broken?
Try: print $age->deltas, "\n"; If the output from that doesn't look right to you please send it on to the list. Code (DateTime is the current version available from CPAN): #!/usr/bin/perl use DateTime; $birth=DateTime->new(year=>1968,month=>6,day=>28); print $birth->ymd."\n"; $today=DateTime->today; print $today->ymd."\n"; $age=$today-$birth; print "Years:".$age->years."\n"; print "Months:".$age->months."\n"; print "Days:".$age->days."\n"; print "Deltas:".$age->deltas."\n"; print "Delta Months:".$age->delta_months."\n"; print "Delta Days:".$age->delta_days."\n"; Output: 1968-06-28 2003-08-17 Years:0 Months:0 Days:2 Deltas:10 Delta Months:0 Delta Days:12833 Again I fail to see the logic or even value in the DateTime::Duration behaving as above. But, I'm sure I'm probably just missing something important. The only one that does makes since is Deltas but only because it is returning a hash that has 10 elements in it. The Delta Days is sort of interesting but its seems like a lot of work for me to figure out the number of years from that especially when I think the point of this is to take into account all the strange ness that goes on between missing days seconds etc that go on over time. Perhaps I'm just approaching this all wrong. I'm just looking for a simple way to compute some ones age today.
Subtraction Broken?
I'm not sure if I'm doing something really wrong or if things are broke but with this code: #!/usr/bin/perl use DateTime; $birth=DateTime->new(year=>1968,month=>6,day=>28); print $birth->ymd."\n"; $today=DateTime->today; print $today->ymd."\n"; $age=$today-$birth; print $age->years."\n"; I get this output: 1968-06-28 2003-08-17 0 That zero sure doesn't seem correct to me.
DateTime used with Class::DBI
I'm not sure anyone is interested but I thought I would pass this along. I have started using Class::DBI and was hoping I could also use DateTime with it. Class::DBI has some hooks to allow for any type of Object to represent Time. However the one limitation it has is that you must be able to call a method with no parameters to produce the proper output for the database. So the only way I could use DateTime with it is if $datetime->somename() produces the correct format for the database I'm using. I have taken a look at the DateTime-Format-MySQL and it can produce the formats required however with out being able to get the format through a call as described above it will never work with Class::DBI. This isn't exactly a DateTime problem or a Class::DBI problem or a Database problem just an interaction issue that someone may or may not be interested in looking at. However as the two objects operate today I don't see them being compatible. If you are interested and have any additional questions feel free to ask. Thanks Matthew McGillis