Re: New Module: Time::Seconds::GroupedBy
At 06:00 AM 2004-07-14, Bruno Negrão wrote: Hi Sean, i coudn't get what you mean (it is too colloquial for my poor english understanding...) What do you mean? Should i keep on this project or give it up? Oops, sorry. I think you should go ahead with your project. -- Sean M. Burkehttp://search.cpan.org/~sburke/
Re: new module: Time::Seconds::GroupedBy
* Dave Rolsky [EMAIL PROTECTED] [2004-07-14 03:25]: Ah, so you reinvented DateTime::Format::Duration. Actually, I think he reinvented Time::Seconds, which is part of the Time::Piece distro. Well, both, I guess. Goes to show how many, *many* people have written this sort of thing before in various forms and shapes. Regards, -- Aristotle If you can't laugh at yourself, you don't take life seriously enough.
Re: new module: Time::Seconds::GroupedBy
Actually, I think he reinvented Time::Seconds, which is part of the Time::Piece distro. No guys, Time::Seconds doesn't give the same answer my module does. Time::Seconds converts seconds entirely in minutes or hours or days or etc. For example, it says that 7341 seconds are: 2,03916 hours 122,35 minutes 0,08 days etc. I really Think i should extend Time::Seconds instead of publishing a new module, but i couldn´t contatc the authors of that module. Time::Duration addresses the same calculation i'm doing, but the way it gives the answer is not that good. i think i'gonna talk with DateTime group a litle bit, they are more inserted in this context. thank you all, bruno negrao.
Re: New Module: Time::Seconds::GroupedBy
Enh, sorta. Most of the work of Time::Duration is figuring out how to whittle down a multiple-units expression of a time to a particular degree of concision. It also doesn't have the concept of month. You're probably better off just starting over, since stuff like $mins = int($secs) / 60; $secs -= $mins * 60; is neither complex nor error-prone. Hi Sean, i coudn't get what you mean (it is too colloquial for my poor english understanding...) What do you mean? Should i keep on this project or give it up? bruno.
Re: new module: Time::Seconds::GroupedBy
On Tue, Jul 13, 2004 at 09:01:30PM -0300, Bruno Negr?o wrote: Ah, so you reinvented DateTime::Format::Duration. use DateTime::Format::Duration; my $fmt = DateTime::Format::Duration-new( pattern = '%H hours, %M minutes, %S seconds', normalize = 1, ); print $fmt-format_duration_from_deltas( seconds = 7341, ), \n; Oh, what a sadness. Indeed i never saw the DateTime project before. But still my module is far easier to use than DateTime::Format::Duration. Do you believe it is worth to publish it in Time::Seconds::GroupBy? I would rather see more standardization on the use of the DateTime project, in much the same way that people think of DBI when they think of accessing databases through Perl. In this case, perhaps some clear documentation and examples (just like the one above) would be the best solution. I think if such a solution was easy to find on Google and clearly documented, people would use it, especially once there is more awareness of DateTime as a comprehensive date time solution for Perl. Mark -- . . . . . . . . . . . . . . . . . . . . . . . . . . . Mark StosbergPrincipal Developer [EMAIL PROTECTED] Summersault, LLC 765-939-9301 ext 202 database driven websites . . . . . http://www.summersault.com/ . . . . . . . .
Re: new module: Time::Seconds::GroupedBy
I would rather see more standardization on the use of the DateTime project, in much the same way that people think of DBI when they think of accessing databases through Perl. In this case, perhaps some clear documentation and examples (just like the one above) would be the best solution. I think if such a solution was easy to find on Google and clearly documented, people would use it, especially once there is more awareness of DateTime as a comprehensive date time solution for Perl. I agree Mark, i've posted my module on the DateTime mailing list. Let's see what they say about it. But i think the DateTime project is not gaining fair promotion once their modules are not even appearing on the main Module List in the cpan's site at http://www.cpan.org/modules/00modlist.long.html. If people should concentrate effort in making this framework the solution for Dates and times related problems, the DateTime namespace should at least appear on the Module List, right? Regards, bruno.
Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
On Wed, Jul 14, 2004 at 01:24:43PM -0300, Bruno Negr?o wrote: I agree Mark, i've posted my module on the DateTime mailing list. Let's see what they say about it. But i think the DateTime project is not gaining fair promotion once their modules are not even appearing on the main Module List in the cpan's site at http://www.cpan.org/modules/00modlist.long.html. If people should concentrate effort in making this framework the solution for Dates and times related problems, the DateTime namespace should at least appear on the Module List, right? I think there is a separate more general issue that the module list is losing relevance. I think a lot of people (like myself), use http://search.cpan.org as a primary method for finding useful modules. As a CPAN user, I don't consult the list when looking for modules. As a module writer, I have abandoned caring if my modules appear on the list, because I have the perception it's not used much anymore. So I would say a more important issue is that the DateTime modules don't show up in the first 100 results for Date on that website: http://search.cpan.org/search?m=allq=dates=1n=100 I think part of the solution to fix that is to have more contributions to the CPAN ratings system, and consider the ratings in the search results. Mark -- . . . . . . . . . . . . . . . . . . . . . . . . . . . Mark StosbergPrincipal Developer [EMAIL PROTECTED] Summersault, LLC 765-939-9301 ext 202 database driven websites . . . . . http://www.summersault.com/ . . . . . . . .
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
[EMAIL PROTECTED] (Mark Stosberg) writes: I think part of the solution to fix that is to have more contributions to the CPAN ratings system, and consider the ratings in the search results. The searching in search.cpan.org is, unfortunately, pretty awful. At some point I plan to sit down and try using Plucene as a search engine for module data. This would, of course, be easier if the search.cpan.org code was more widely available. *cough* -- Death Damned electrons get into everything. Death I found them in my BUTTERDISH just the other day.
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
I think there is a separate more general issue that the module list is losing relevance. I think a lot of people (like myself), use http://search.cpan.org as a primary method for finding useful modules. As a CPAN user, I don't consult the list when looking for modules. As a module writer, I have abandoned caring if my modules appear on the list, because I have the perception it's not used much anymore. Since i heard this from you, i have always had the idea that the modules in the Module List were the mainstream modules and we should consider them first than the other ones in search.cpan.org. Hmm, i think everybody who is new to perl think the same way i was thinking and it takes a long time to realize that the Module List is not the main source for the modules, or the main inspiration source for namespaces. No, i really endorse that the most important(or popular) modules and/or namespaces shall appear in the Module List. bruno.
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
Simon Cozens sent the following bits through the ether: The searching in search.cpan.org is, unfortunately, pretty awful. At some point I plan to sit down and try using Plucene as a search engine for module data. I thought that would be a good idea too, so I tried it. It works *fairly* well. http://search.cpan.org/dist/CPAN-IndexPod/ Leon -- Leon Brocard.http://www.astray.com/ scribot.http://www.scribot.com/ ... Stupid is a boundless concept.
Re: new module: Time::Seconds::GroupedBy
On Wed, 14 Jul 2004, Bruno Negrão wrote: I would rather see more standardization on the use of the DateTime project, in much the same way that people think of DBI when they think of accessing databases through Perl. In this case, perhaps some clear documentation and examples (just like the one above) would be the best solution. I think if such a solution was easy to find on Google and clearly documented, people would use it, especially once there is more awareness of DateTime as a comprehensive date time solution for Perl. I agree Mark, i've posted my module on the DateTime mailing list. Let's see what they say about it. But i think the DateTime project is not gaining fair promotion once their modules are not even appearing on the main Module List in the cpan's site at http://www.cpan.org/modules/00modlist.long.html. Some of them are, but not all. Frankly, I don't think most people really look at the list much, nor do most people consider it authoritative. What'd help more would be some articles on the project. I've been wanting to write one for a while, but I'm always short on time. If people should concentrate effort in making this framework the solution for Dates and times related problems, the DateTime namespace should at least appear on the Module List, right? Some of them _are_ registered, but that document you're referring to hasn't been regenerated since 2002/08/27! I wish the CPAN folks would just remove it if it won't be generated regularly. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
On Wed, Jul 14, 2004 at 06:08:16PM +0100, Leon Brocard wrote: Simon Cozens sent the following bits through the ether: The searching in search.cpan.org is, unfortunately, pretty awful. At some point I plan to sit down and try using Plucene as a search engine for module data. I thought that would be a good idea too, so I tried it. It works *fairly* well. http://search.cpan.org/dist/CPAN-IndexPod/ Does META.yaml have a place for keyowrds? It would be nice if it did and if search.cpan.org indexed it. That would mean that it would be no longer necessary to name your module along the lines of XML::HTTP::Network::Daemon::TextProcessing::Business::Papersize::GIS so that people can find it, F
Re: new module: Time::Seconds::GroupedBy
* Dave Rolsky [EMAIL PROTECTED] [2004-07-14 19:26]: Some of them _are_ registered, but that document you're referring to hasn't been regenerated since 2002/08/27! I wish the CPAN folks would just remove it if it won't be generated regularly. Does anyone else here think that the list should probably just be done away with entirely? Regards, -- Aristotle If you can't laugh at yourself, you don't take life seriously enough.
Re: new module: Time::Seconds::GroupedBy
On Wed, 14 Jul 2004, A. Pagaltzis wrote: * Dave Rolsky [EMAIL PROTECTED] [2004-07-14 19:26]: Some of them _are_ registered, but that document you're referring to hasn't been regenerated since 2002/08/27! I wish the CPAN folks would just remove it if it won't be generated regularly. Does anyone else here think that the list should probably just be done away with entirely? Given the fact that most authors seem to not register their stuff, the [EMAIL PROTECTED] list is slow as heck, and that the web pages never get regenerated, yes. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
[EMAIL PROTECTED] (Scott W Gifford) writes: It would be interesting to calculate the importance of a module by how many other modules link to it, either via a use statement or by reference in the POD, much like Google does with Web page links. Someone's already done this for CPAN, but I can't find it at the moment. There's a project called Nutch that has abstracted out much of PageRank and that sort of thing that would be useful, if anybody is interested. Algorithm::PageRank has also abstracted out much of PageRank... :) -- Oh dear. I've just realised that my fvwm config lasted longer than my marriage, in that case. - Anonymous
Re: new module: Time::Seconds::GroupedBy
* Dave Rolsky [EMAIL PROTECTED] [2004-07-14 19:41]: Does anyone else here think that the list should probably just be done away with entirely? Given the fact that most authors seem to not register their stuff, the [EMAIL PROTECTED] list is slow as heck, and that the web pages never get regenerated, yes. Now the question is: how would we make that happen? Regards, -- Aristotle If you can't laugh at yourself, you don't take life seriously enough.
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
* Scott W Gifford [EMAIL PROTECTED] [2004-07-14 19:38]: It would be interesting to calculate the importance of a module by how many other modules link to it, either via a use statement or by reference in the POD, much like Google does with Web page links. I was thinking the same thing, and I remember that someone actually posted results from working code for something like that a while back. I don't have the time to dig through the archives right now, or I'd shake it up. There's a project called Nutch that has abstracted out much of PageRank and that sort of thing that would be useful, if anybody is interested. Nutch is written in Java, unfortunately for we Perl folks, but isn't too hard to work with. :) And as Lucene/Plucene show, it doesn't have to be difficult to reimplement good libraries in Perl, either. :-) Regards, -- Aristotle If you can't laugh at yourself, you don't take life seriously enough.
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
On Wed, Jul 14, 2004 at 06:30:59PM +0100, Fergal Daly wrote: On Wed, Jul 14, 2004 at 06:08:16PM +0100, Leon Brocard wrote: Simon Cozens sent the following bits through the ether: The searching in search.cpan.org is, unfortunately, pretty awful. At some point I plan to sit down and try using Plucene as a search engine for module data. I thought that would be a good idea too, so I tried it. It works *fairly* well. http://search.cpan.org/dist/CPAN-IndexPod/ Does META.yaml have a place for keyowrds? It would be nice if it did and if search.cpan.org indexed it. That would mean that it would be no longer necessary to name your module along the lines of XML::HTTP::Network::Daemon::TextProcessing::Business::Papersize::GIS so that people can find it, That's what the Description field is for. Tim.
Re: Finding prior art Perl modules (was: new module: Time::Seconds::GroupedBy)
On Wed, Jul 14, 2004 at 10:34:08PM +0100, Tim Bunce wrote: On Wed, Jul 14, 2004 at 06:30:59PM +0100, Fergal Daly wrote: XML::HTTP::Network::Daemon::TextProcessing::Business::Papersize::GIS so that people can find it, That's what the Description field is for. There's a Description field? I accept responsibility for not knowing about this, I've never made an effort to see what is available. However, if search.cpan.org had allowed me to search by Description field I probably would have included one in all of my modules, F
New Module: Time::Seconds::GroupedBy
Hi all, I've made a new module, I'm thinking to call it Time::Seconds::GroupedBy. It is designed to convert an amount of seconds in other time units. I'm calling time units SECONDS, MINUTES, HOURS, DAYS, MONTHS, and YEARS . The user defines which will be the time unit to group the amount of seconds. Using my module, the following test code: use strict; my $seconds = 31556931; foreach ('MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS') { my $s = new GroupedBy ( $_ ); my ($secs, $mins, $hours, $days, $months, $years) = $s-calculate($seconds); print Grouping by $_, $seconds seconds are:\n , $years years, $months months, $days days, $hours hours,, $mins mins, $secs seconds.\n\n; } Will bring this output: Grouping by MINS, 31556931 seconds are: 0 years, 0 months, 0 days, 0 hours, 525948 mins, 51 seconds. Grouping by HOURS, 31556931 seconds are: 0 years, 0 months, 0 days, 8765 hours, 48 mins, 51 seconds. Grouping by DAYS, 31556931 seconds are: 0 years, 0 months, 365 days, 5 hours, 48 mins, 51 seconds. Grouping by MONTHS, 31556931 seconds are: 0 years, 12 months, 5 days, 5 hours, 48 mins, 51 seconds. Grouping by YEARS, 31556931 seconds are: 1 years, 0 months, 0 days, 0 hours, 0 mins, 1 seconds. The draft code of the module is bellow, package GroupedBy; sub new { my $class = shift; my $self = {}; bless ( $self, $class ); my $GroupedBy = shift; # Amount of Seconds input by the user (set by calculate() method) $self-{SECONDS}; # Initializing data about years, months, days, hours and minutes; $self-{SECS} = { result = 0 }; # A minute is 60 seconds $self-{MINS} = { inSecs = 60, opId = 1, took = 0, result = 0 }; # An hour is 60 * 60 seconds $self-{HOURS} = { inSecs = 3600, opId = 2, took = 0, result = 0 }; # A day is 60 * 60 * 24 seconds $self-{DAYS} = { inSecs = 86400, opId = 3, took = 0, result = 0 }; # A month is 60 * 60 * 24 * 30 seconds $self-{MONTHS} = { inSecs = 2592000, opId = 4, took = 0, result = 0 }; # Year is 60 * 60 * 24 * 365.24225 = 31556930.4 seconds (we'll ignore 0.4 secs) $self-{YEARS} = { inSecs = 31556930, opId = 5, took = 0, result = 0 }; # OPID - operation ID, is a number indentifying the kind of grouping that # was chosen by the user. Each grouping requires a diferent operation to # calculate the resulting values. $self-{OPID} = $self-{$GroupedBy}-{opId}; die Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS' unless defined $self-{OPID}; return $self; } sub calculate { # returns: Array: the results of the calculus my $self = shift; $self-{SECONDS} = shift; $self-_clean(); my @result = ( $self-_years(), $self-_months(), $self-_days(), $self-_hours(), $self-_mins(), $self-_secs() ); return reverse @result; } sub groupedBy { # returns: String: the current GROUPED_BY type my $self = shift; my $GroupedBy = shift; $self-{OPID} = $self-($GroupedBy)-{opId}; die Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS' unless defined $self-{OPID}; return $GroupedBy; } # Cleans(set to 0)the 'took' and 'result' counters for all groups sub _clean { # returns: nothing my $self = shift; foreach ( qw ( SECS MINS HOURS DAYS MONTHS YEARS ) ) { $self-{$_}-{took} = 0; $self-{$_}-{result} = 0; } } sub _secs { # returns: Integer: the result my $self = shift; my $name = SECS; $self-{$name}-{result} = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took} - $self-{MINS}-{took}; return $self-{$name}-{result}; } sub _mins { # returns: Integer: the result my $self = shift; my $name = MINS; if ( $self-{OPID} = 1 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; } } return $self-{$name}-{result}; } sub _hours { # returns: Integer: the result my $self = shift; my $name = HOURS; if ( $self-{OPID} = 2 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; } } return $self-{$name}-{result}; } sub _days { # returns: Integer: the result my $self = shift; my $name = DAYS; if ( $self-{OPID} = 3 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; } } return $self-{$name}-{result}; } sub _months { # returns:
new module: Time::Seconds::GroupedBy
Hi all,I've made a new module, I'm thinking to call it Time::Seconds::GroupedBy. Itis designed to convert an amount of seconds in other time units. I'm callingtime units SECONDS, MINUTES, HOURS, DAYS, MONTHS, and YEARS . The userdefines which will be the time unit to group the amount of seconds.Using my module, the following test code:use strict;my $seconds = 31556931;foreach ('MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS') { my $s = new GroupedBy ( $_ ); my ($secs, $mins, $hours, $days, $months, $years) = $s-calculate($seconds); print "Grouping by $_, $seconds seconds are:\n ", " $years years, $months months, $days days, $hours hours,", " $mins mins, $secs seconds.\n\n";}Will bring this output:Grouping by MINS, 31556931 seconds are: 0 years, 0 months, 0 days, 0 hours, 525948 mins, 51 seconds.Grouping by HOURS, 31556931 seconds are: 0 years, 0 months, 0 days, 8765 hours, 48 mins, 51 seconds.Grouping by DAYS, 31556931 seconds are: 0 years, 0 months, 365 days, 5 hours, 48 mins, 51 seconds.Grouping by MONTHS, 31556931 seconds are: 0 years, 12 months, 5 days, 5 hours, 48 mins, 51 seconds.Grouping by YEARS, 31556931 seconds are: 1 years, 0 months, 0 days, 0 hours, 0 mins, 1 seconds.The draft code of the module is bellow,package GroupedBy;sub new {my $class = shift;my $self = {};bless ( $self, $class );my $GroupedBy = shift;# Amount of Seconds input by the user (set by calculate() method)$self-{SECONDS};# Initializing data about years, months, days, hours and minutes;$self-{SECS} = { result = 0 };# A minute is 60 seconds$self-{MINS} = { inSecs = 60, opId = 1, took = 0, result = 0 };# An hour is 60 * 60 seconds$self-{HOURS} = { inSecs = 3600, opId = 2, took = 0, result = 0 };# A day is 60 * 60 * 24 seconds$self-{DAYS} = { inSecs = 86400, opId = 3, took = 0, result = 0 };# A month is 60 * 60 * 24 * 30 seconds$self-{MONTHS} = { inSecs = 2592000, opId = 4, took = 0, result = 0 };# Year is 60 * 60 * 24 * 365.24225 = 31556930.4 seconds (we'll ignore 0.4 secs)$self-{YEARS} = { inSecs = 31556930, opId = 5, took = 0, result = 0 };# OPID - operation ID, is a number indentifying the kind of grouping that# was chosen by the user. Each grouping requires a diferent operation to# calculate the resulting values.$self-{OPID} = $self-{$GroupedBy}-{opId};die "Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS'" unless defined $self-{OPID};return $self;}sub calculate { # returns: Array: the results of the calculusmy $self = shift;$self-{SECONDS} = shift;$self-_clean();my @result = ( $self-_years(), $self-_months(), $self-_days(), $self-_hours(), $self-_mins(), $self-_secs() );return reverse @result;}sub groupedBy { # returns: String: the current GROUPED_BY typemy $self = shift;my $GroupedBy = shift;$self-{OPID} = $self-($GroupedBy)-{opId};die "Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS'" unless defined $self-{OPID};return $GroupedBy;}# Cleans(set to 0)the 'took' and 'result' counters for all groupssub _clean { # returns: nothingmy $self = shift;foreach ( qw ( SECS MINS HOURS DAYS MONTHS YEARS ) ) { $self-{$_}-{took} = 0; $self-{$_}-{result} = 0;}}sub _secs { # returns: Integer: the resultmy $self = shift;my $name = "SECS";$self-{$name}-{result} = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took} - $self-{MINS}-{took};return $self-{$name}-{result};}sub _mins { # returns: Integer: the resultmy $self = shift;my $name = "MINS";if ( $self-{OPID} = 1 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; }}return $self-{$name}-{result};}sub _hours { # returns: Integer: the resultmy $self = shift;my $name = "HOURS";if ( $self-{OPID} = 2 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; }}return $self-{$name}-{result};}sub _days { # returns: Integer: the resultmy $self = shift;my $name = "DAYS";if ( $self-{OPID} = 3 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; }}return $self-{$name}-{result};}sub _months { # returns: Integer: the resultmy $self = shift;my $name = "MONTHS";if ( $self-{OPID} = 4 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 )
new module: Time::Seconds::GroupedBy
Hi all,I've made a new module, I'm thinking to call it Time::Seconds::GroupedBy. Itis designed to convert an amount of seconds in other time units. I'm callingtime units SECONDS, MINUTES, HOURS, DAYS, MONTHS, and YEARS . The userdefines which will be the time unit to group the amount of seconds.Using my module, the following test code:use strict;my $seconds = 31556931;foreach ('MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS') { my $s = new GroupedBy ( $_ ); my ($secs, $mins, $hours, $days, $months, $years) = $s-calculate($seconds); print "Grouping by $_, $seconds seconds are:\n ", " $years years, $months months, $days days, $hours hours,", " $mins mins, $secs seconds.\n\n";}Will bring this output:Grouping by MINS, 31556931 seconds are: 0 years, 0 months, 0 days, 0 hours, 525948 mins, 51 seconds.Grouping by HOURS, 31556931 seconds are: 0 years, 0 months, 0 days, 8765 hours, 48 mins, 51 seconds.Grouping by DAYS, 31556931 seconds are: 0 years, 0 months, 365 days, 5 hours, 48 mins, 51 seconds.Grouping by MONTHS, 31556931 seconds are: 0 years, 12 months, 5 days, 5 hours, 48 mins, 51 seconds.Grouping by YEARS, 31556931 seconds are: 1 years, 0 months, 0 days, 0 hours, 0 mins, 1 seconds.The draft code of the module is bellow,package GroupedBy;sub new {my $class = shift;my $self = {};bless ( $self, $class );my $GroupedBy = shift;# Amount of Seconds input by the user (set by calculate() method)$self-{SECONDS};# Initializing data about years, months, days, hours and minutes;$self-{SECS} = { result = 0 };# A minute is 60 seconds$self-{MINS} = { inSecs = 60, opId = 1, took = 0, result = 0 };# An hour is 60 * 60 seconds$self-{HOURS} = { inSecs = 3600, opId = 2, took = 0, result = 0 };# A day is 60 * 60 * 24 seconds$self-{DAYS} = { inSecs = 86400, opId = 3, took = 0, result = 0 };# A month is 60 * 60 * 24 * 30 seconds$self-{MONTHS} = { inSecs = 2592000, opId = 4, took = 0, result = 0 };# Year is 60 * 60 * 24 * 365.24225 = 31556930.4 seconds (we'll ignore 0.4 secs)$self-{YEARS} = { inSecs = 31556930, opId = 5, took = 0, result = 0 };# OPID - operation ID, is a number indentifying the kind of grouping that# was chosen by the user. Each grouping requires a diferent operation to# calculate the resulting values.$self-{OPID} = $self-{$GroupedBy}-{opId};die "Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS'" unless defined $self-{OPID};return $self;}sub calculate { # returns: Array: the results of the calculusmy $self = shift;$self-{SECONDS} = shift;$self-_clean();my @result = ( $self-_years(), $self-_months(), $self-_days(), $self-_hours(), $self-_mins(), $self-_secs() );return reverse @result;}sub groupedBy { # returns: String: the current GROUPED_BY typemy $self = shift;my $GroupedBy = shift;$self-{OPID} = $self-($GroupedBy)-{opId};die "Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS'" unless defined $self-{OPID};return $GroupedBy;}# Cleans(set to 0)the 'took' and 'result' counters for all groupssub _clean { # returns: nothingmy $self = shift;foreach ( qw ( SECS MINS HOURS DAYS MONTHS YEARS ) ) { $self-{$_}-{took} = 0; $self-{$_}-{result} = 0;}}sub _secs { # returns: Integer: the resultmy $self = shift;my $name = "SECS";$self-{$name}-{result} = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took} - $self-{MINS}-{took};return $self-{$name}-{result};}sub _mins { # returns: Integer: the resultmy $self = shift;my $name = "MINS";if ( $self-{OPID} = 1 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; }}return $self-{$name}-{result};}sub _hours { # returns: Integer: the resultmy $self = shift;my $name = "HOURS";if ( $self-{OPID} = 2 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; }}return $self-{$name}-{result};}sub _days { # returns: Integer: the resultmy $self = shift;my $name = "DAYS";if ( $self-{OPID} = 3 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; }}return $self-{$name}-{result};}sub _months { # returns: Integer: the resultmy $self = shift;my $name = "MONTHS";if ( $self-{OPID} = 4 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 )
Re: new module: Time::Seconds::GroupedBy
Is there any reason to use it in preference to DateTime::Duration? Hi Aristotle, My module differs from DateTime::Duration because it is not dealing with dates. It does not try to foresee which is a future of past date based in a bunch of seconds. It just provide a means to calculate a time quantity that is more human readable than a big number of seconds. For example, if you're making a big file transfer over the network everyday, and this transfer takes 7341 seconds to finish, and you want to receive a report saying how much time the transfer took, indeed, you want to know that the file transfer took 2 hours, 2 minutes and 21 seconds (7341 seconds grouped by hours). My module will calculate this conversion of seconds to a bigger time group, HOURS, in this case. To do this with my module you would: # - converting seconds to hours - new $time = new Time::Seconds::GroupedBy('HOURS'); my ($secs, $mins, $hours) = $time-calculate(7341); print $hours hours $mins minutes $secs seconds\n; So, if you have more seconds to calculate, maybe hours is a small quantity, then you may chose to group seconds in a bigger group, like DAYS. For example, to know that 734100 seconds are equivalent to 8 days, 11 hours, 55 mins, 0 seconds. # - converting seconds to days - $time-groubBy('DAYS'); my ($secs, $mins, $hours, $days) = $time-calculate(734100); When DAYS is a small group, you could group them by MONTHS, ultimately, by YEARS. Well, it's usefull for me. I didn't find yet a module providing this kind of conversion... what do you think? A hug, bruno.
Re: new module: Time::Seconds::GroupedBy
* Bruno Negrão [EMAIL PROTECTED] [2004-07-13 23:53]: Hi Aristotle, My module differs from DateTime::Duration because it is not dealing with dates. It does not try to foresee which is a future of past date based in a bunch of seconds. It just provide a means to calculate a time quantity that is more human readable than a big number of seconds. You mean, it deals with a... duration? To do this with my module you would: # - converting seconds to hours - new $time = new Time::Seconds::GroupedBy('HOURS'); my ($secs, $mins, $hours) = $time-calculate(7341); print $hours hours $mins minutes $secs seconds\n; Ah, so you reinvented DateTime::Format::Duration. use DateTime::Format::Duration; my $fmt = DateTime::Format::Duration-new( pattern = '%H hours, %M minutes, %S seconds', normalize = 1, ); print $fmt-format_duration_from_deltas( seconds = 7341, ), \n; Well, it's usefull for me. I didn't find yet a module providing this kind of conversion... I haven't done this before either. It took me about 10 minutes of research on CPAN. Maybe my advantage was that I knew about the DateTime project which set out to solve the issue of using Perl for date and time math Once And For All. Regards, -- Aristotle If you can't laugh at yourself, you don't take life seriously enough.
Re: new module: Time::Seconds::GroupedBy
Hm It just provide a means to calculate a time quantity that is more human readable than a big number of seconds. You mean, it deals with a... duration? Can I call it time quantity?! ;-) Ah, so you reinvented DateTime::Format::Duration. use DateTime::Format::Duration; my $fmt = DateTime::Format::Duration-new( pattern = '%H hours, %M minutes, %S seconds', normalize = 1, ); print $fmt-format_duration_from_deltas( seconds = 7341, ), \n; Oh, what a sadness. Indeed i never saw the DateTime project before. But still my module is far easier to use than DateTime::Format::Duration. Do you believe it is worth to publish it in Time::Seconds::GroupBy? bruno.
Re: new module: Time::Seconds::GroupedBy
On 7/13/2004 8:01 PM, Bruno Negrão wrote: Oh, what a sadness. Indeed i never saw the DateTime project before. But still my module is far easier to use than DateTime::Format::Duration. Do you believe it is worth to publish it in Time::Seconds::GroupBy? Not sadness, experience. Actually this was an exercise on the perl QotW (Quiz of the Week) mailing list[1]. So you are not the only one to write this code and then throw it away :-) It does seem this task is adequately provided for by at least 2 other modules, so... Regards, Randy. 1. http://perl.plover.com/qotw/
Re: New Module: Time::Seconds::GroupedBy
Seems related to, and an extension of, Time::Duration. Perhaps you could extend that module rather than create a new one. Yes, really were addressing the same problem. However, Time::Duration doesn't output the time numbers separately, instead, it throws a static string written in english saying the results. I don't think this is adequate. Maybe extending this module would be a good idea... i'll read it. Regards, bruno. Tim. Using my module, the following test code: use strict; my $seconds = 31556931; foreach ('MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS') { my $s = new GroupedBy ( $_ ); my ($secs, $mins, $hours, $days, $months, $years) = $s-calculate($seconds); print Grouping by $_, $seconds seconds are:\n , $years years, $months months, $days days, $hours hours,, $mins mins, $secs seconds.\n\n; } Will bring this output: Grouping by MINS, 31556931 seconds are: 0 years, 0 months, 0 days, 0 hours, 525948 mins, 51 seconds. Grouping by HOURS, 31556931 seconds are: 0 years, 0 months, 0 days, 8765 hours, 48 mins, 51 seconds. Grouping by DAYS, 31556931 seconds are: 0 years, 0 months, 365 days, 5 hours, 48 mins, 51 seconds. Grouping by MONTHS, 31556931 seconds are: 0 years, 12 months, 5 days, 5 hours, 48 mins, 51 seconds. Grouping by YEARS, 31556931 seconds are: 1 years, 0 months, 0 days, 0 hours, 0 mins, 1 seconds. The draft code of the module is bellow, package GroupedBy; sub new { my $class = shift; my $self = {}; bless ( $self, $class ); my $GroupedBy = shift; # Amount of Seconds input by the user (set by calculate() method) $self-{SECONDS}; # Initializing data about years, months, days, hours and minutes; $self-{SECS} = { result = 0 }; # A minute is 60 seconds $self-{MINS} = { inSecs = 60, opId = 1, took = 0, result = 0 }; # An hour is 60 * 60 seconds $self-{HOURS} = { inSecs = 3600, opId = 2, took = 0, result = 0 }; # A day is 60 * 60 * 24 seconds $self-{DAYS} = { inSecs = 86400, opId = 3, took = 0, result = 0 }; # A month is 60 * 60 * 24 * 30 seconds $self-{MONTHS} = { inSecs = 2592000, opId = 4, took = 0, result = 0 }; # Year is 60 * 60 * 24 * 365.24225 = 31556930.4 seconds (we'll ignore 0.4 secs) $self-{YEARS} = { inSecs = 31556930, opId = 5, took = 0, result = 0 }; # OPID - operation ID, is a number indentifying the kind of grouping that # was chosen by the user. Each grouping requires a diferent operation to # calculate the resulting values. $self-{OPID} = $self-{$GroupedBy}-{opId}; die Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS' unless defined $self-{OPID}; return $self; } sub calculate { # returns: Array: the results of the calculus my $self = shift; $self-{SECONDS} = shift; $self-_clean(); my @result = ( $self-_years(), $self-_months(), $self-_days(), $self-_hours(), $self-_mins(), $self-_secs() ); return reverse @result; } sub groupedBy { # returns: String: the current GROUPED_BY type my $self = shift; my $GroupedBy = shift; $self-{OPID} = $self-($GroupedBy)-{opId}; die Unvalid value. Valid values are 'MINS', 'HOURS', 'DAYS', 'MONTHS', 'YEARS' unless defined $self-{OPID}; return $GroupedBy; } # Cleans(set to 0)the 'took' and 'result' counters for all groups sub _clean { # returns: nothing my $self = shift; foreach ( qw ( SECS MINS HOURS DAYS MONTHS YEARS ) ) { $self-{$_}-{took} = 0; $self-{$_}-{result} = 0; } } sub _secs { # returns: Integer: the result my $self = shift; my $name = SECS; $self-{$name}-{result} = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took} - $self-{MINS}-{took}; return $self-{$name}-{result}; } sub _mins { # returns: Integer: the result my $self = shift; my $name = MINS; if ( $self-{OPID} = 1 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took} - $self-{HOURS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; } } return $self-{$name}-{result}; } sub _hours { # returns: Integer: the result my $self = shift; my $name = HOURS; if ( $self-{OPID} = 2 ) { my $secsLeft = $self-{SECONDS} - $self-{YEARS}-{took} - $self-{MONTHS}-{took} - $self-{DAYS}-{took}; $self-{$name}-{result} = int($secsLeft / $self-{$name}-{inSecs}); if ( $self-{$name}-{result} != 0 ) { $self-{$name}-{took} = $self-{$name}-{result} * $self-{$name}-{inSecs}; } } return $self-{$name}-{result}; } sub _days { # returns: Integer: the result my $self = shift;
Re: new module: Time::Seconds::GroupedBy
On Wed, 14 Jul 2004, A. Pagaltzis wrote: Ah, so you reinvented DateTime::Format::Duration. Actually, I think he reinvented Time::Seconds, which is part of the Time::Piece distro. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/