A Date with CPAN, Part 11: Sweet Release

[This is a post in my latest long-ass series.  You may want to begin at the beginning.  I do not promise that the next post in the series will be next week.  Just that I will eventually finish it, someday.  Unless I get hit by a bus.

IMPORTANT NOTE!  When I provide you links to code on GitHub, I’m giving you links to particular commits.  This allows me to show you the code as it was at the time the blog post was written and insures that the code references will make sense in the context of this post.  Just be aware that the latest version of the code may be very different.]

Last time I cleaned up most of the remaining CPAN Testers failures.  This time I’m getting ready for the first official release.  There isn’t a lot to talk about here, so this will be (uncharacteristically) a short entry in the series.

The first thing to note is that, despite the fact that I cleared up a whole bunch of the problems that CPAN Testers noted, there were still a couple left.  One of them proved to be super-simple to clear up.  See, I’ve been trying to be more specific lately with my use of whitespace in regular expressions.  Too often we just write \s when we really don’t mean that.  If it’s really okay for \n to match, then \s is what you meant, sure.  But, if not, then you probably meant \h instead.  And I’ve been trying to default to using \h and then only changing it to \s if I really do mean for it to match newlines as well.

In general, I think this is a good habit.  However, there is one downside, which I never actually realized before CPAN Testers was kind enough to point it out to me: \h only came along in Perl 5.10.  So, if you need your regexes to work on Perl 5.8, no \h for you.  Now, I’m not saying that I definitely promise to maintain compatibility with 5.8 for Date::Easy for all time.  But, until there’s a compelling reason not to, why not?  All my uses of \h were in unit tests, and it was trivial enough to change to \s in these cases.  And it didn’t really change any functionality.  So I just made that simple change.

There was one other CPAN Tester failure, but it proved too weird to deal with.  It seems to only affect FreeBSD, and only on Perls prior to 5.12, and only on 32-bit machines (but not all of them).  Plus it’s one of those errors which should be impossible but is happening anyway.  I’ll get serious about tracking it down at some point, but, for right now, I think it’s fine to have a few failures.  This last dev release got a 93% pass rate, and I’m fixing some of those failures (as noted above), so hopefully the next release will be even better.1  And I don’t want to delay an official release any longer.

The main thing I needed to work on was adding POD.  So I set to work on that.  It took a while, but I think I got all the details in there.  One thing I noticed while writing the POD was that I didn’t have a time zone method, so I added that.  I once again took a look at DateTime for inspiration, which told me the method name should be spelled time_zone, but it wasn’t very helpful in figuring out what to return.  DateTime::time_zone returns a time zone object, which is more complex than I want to deal with.  For now, I’ve decided to return the time zone abbreviation (i.e. the same as strftime("%Z")).  However, I might change my mind on that if I find (or someone offers up) a compelling reason to return something different.

So I’m very proud to report that you can now download Date::Easy version 0.02 from your friendly local CPAN mirror.  Its functionality is still pretty basic, and there’s lots more I want to do with it, but it’s pretty usable right now.  For instance, here’s a program fragment which would actually do something useful with some of my log files at $work:

use Date::Easy;
use Path::Tiny;

my ($start, $end) = map { date($_) } @ARGV or die("must supply start (end is optional)");
$end //= $start;
$start <= $end or die("start must come before end");

for (my $d = $start; $d <= $end; ++$d)
process_log_file(path($ENV{CEROOT}, qw< var log api-response >, $d->strftime("%Y-%m-%d")));

And I could invoke that program with args like 'last week' yesterday, or just yesterday, or any ol’ date format I felt like.  And it would just work.  And it even has some basic error checking in there too.

As a side note, several people at YAPC::NA came up to me and expressed support for my efforts.  I want to thank all those folks for their encouragement, and I hope this module will be useful for you.  Hopefully it’ll even get even more useful in the future.

Next time, I’ll probably add more UI bits stolen from Date::Piece, but I’m also going to be eating my own dogfood in the meantime, so we’ll see if that leads to anything unforeseen.  But I may also take a break from fiddling with dates for a while and work on a few other things that I’ve been neglecting lately.  Never fear, though: I’ll continue to improve Date::Easy.  But if you think I’m not doing it fast enough, please open an issue for me and I’ll get right on it.  Or just drop me a line and let me know how it’s working for you.  I love to get feedback from the users.


1 As of this writing, the new release has a 100% pass rate.  But I expect to see a few of those pesky FreeBSD failures come back eventually.  It’s only been a couple of days so far.

1 Comment

> For now, I’ve decided to return the time zone abbreviation (i.e. the same as strftime("%Z")). However, I might change my mind on that if I find (or someone offers up) a compelling reason to return something different.

Unfortunately timezone abbreviations (like e.g. PDT) are not unique. See for example http://www.timeanddate.com/time/zones/ ; even near the top you have a few abbreviations with different meanings.

tzinfo names are unique (e.g. Europe/Warsaw), but long. Timezone offsets (+0200 or UTC-2) do not tell anything about daylight saving.

Leave a comment

About Buddy Burden

user-pic 14 years in California, 25 years in Perl, 34 years in computers, 55 years in bare feet.