Categories
Posts in this category
- A shiny perl6.org site
- Creating an entry point for newcomers
- An offer for software developers: free IRC logging
- Sprixel, a 6 compiler powered by JavaScript
- Announcing try.rakudo.org, an interactive Perl 6 shell in your browser
- Another perl6.org iteration
- Blackjack and Perl 6
- Why I commit Crud to the Perl 6 Test Suite
- This Week's Contribution to Perl 6 Week 5: Implement Str.trans
- This Week's Contribution to Perl 6
- This Week's Contribution to Perl 6 Week 8: Implement $*ARGFILES for Rakudo
- This Week's Contribution to Perl 6 Week 6: Improve Book markup
- This Week's Contribution to Perl 6 Week 2: Fix up a test
- This Week's Contribution to Perl 6 Week 9: Implement Hash.pick for Rakudo
- This Week's Contribution to Perl 6 Week 11: Improve an error message for Hyper Operators
- This Week's Contribution to Perl 6 - Lottery Intermission
- This Week's Contribution to Perl 6 Week 3: Write supporting code for the MAIN sub
- This Week's Contribution to Perl 6 Week 1: A website for proto
- This Week's Contribution to Perl 6 Week 4: Implement :samecase for .subst
- This Week's Contribution to Perl 6 Week 10: Implement samespace for Rakudo
- This Week's Contribution to Perl 6 Week 7: Implement try.rakudo.org
- What is the "Cool" class in Perl 6?
- Report from the Perl 6 Hackathon in Copenhagen
- Custom operators in Rakudo
- A Perl 6 Date Module
- Defined Behaviour with Undefined Values
- Dissecting the "Starry obfu"
- The case for distributed version control systems
- Perl 6: Failing Softly with Unthrown Exceptions
- Perl 6 Compiler Feature Matrix
- The first Perl 6 module on CPAN
- A Foray into Perl 5 land
- Gabor: Keep going
- First Grant Report: Structured Error Messages
- Second Grant Report: Structured Error Messages
- Third Grant Report: Structured Error Messages
- Fourth Grant Report: Structured Error Messages
- Google Summer of Code Mentor Recap
- How core is core?
- How fast is Rakudo's "nom" branch?
- Building a Huffman Tree With Rakudo
- Immutable Sigils and Context
- Is Perl 6 really Perl?
- List.classify
- Longest Palindrome by Regex
- Perl 6: Lost in Wonderland
- Lots of momentum in the Perl 6 community
- Monetize Perl 6?
- Musing and the future of feather and the Pugs repository
- Musings on Rakudo's spectest chart
- My first executable from Perl 6
- My first YAPC - YAPC::EU 2010 in Pisa
- Trying to implement new operators - failed
- Programming Languages Are Not Zero Sum
- Perl 6 notes from February 2011
- Notes from the YAPC::EU 2010 Rakudo hackathon
- Let's build an object
- Perl 6 is optimized for fun
- How to get a parse tree for a Perl 6 Program
- Pascal's Triangle in Perl 6
- Perl 6 in 2009
- Perl 6 in 2010
- Perl 6 in 2011 - A Retrospection
- Perl 6 ticket life cycle
- The Perl Survey and Perl 6
- The Perl 6 Advent Calendar
- Perl 6 Questions on Perlmonks
- Physical modeling with Math::Model and Perl 6
- How to Plot a Segment of a Circle with SVG
- Protected Attributes Make No Sense
- Publicity for Perl 6
- PVC - Perl 6 Vocabulary Coach
- Fixing Rakudo Memory Leaks
- Rakudo architectural overview
- Rakudo Rocks
- Rakudo "star" announced
- My personal "I want a PONIE" wish list for Rakudo Star
- Rakudo's rough edges
- Rats and other pets
- The Real World Strikes Back - or why you shouldn't forbid stuff just because you think it's wrong
- Releasing Rakudo made easy
- Set Phasers to Stun!
- Starry Perl 6 obfu
- Recent Perl 6 Developments August 2008
- The State of Regex Modifiers in Rakudo
- Strings and Buffers
- Subroutines vs. Methods - Differences and Commonalities
- A SVG plotting adventure
- A Syntax Highlighter for Perl 6
- Test Suite Reorganization: How to move tests
- The Happiness of Design Convergence
- Thoughts on masak's Perl 6 Coding Contest
- The Three-Fold Function of the Smart Match Operator
- Perl 6 Tidings from September and October 2008
- Perl 6 Tidings for November 2008
- Perl 6 Tidings from December 2008
- Perl 6 Tidings from January 2009
- Perl 6 Tidings from February 2009
- Perl 6 Tidings from March 2009
- Perl 6 Tidings from April 2009
- Perl 6 Tidings from May 2009
- Perl 6 Tidings from May 2009 (second iteration)
- Perl 6 Tidings from June 2009
- Perl 6 Tidings from August 2009
- Perl 6 Tidings from October 2009
- Timeline for a syntax change in Perl 6
- Visualizing match trees
- Want to write shiny SVG graphics with Perl 6? Port Scruffy!
- We write a Perl 6 book for you
- When we reach 100% we did something wrong
- Where Rakudo Lives Now
- Why Rakudo needs NQP
- Why was the Perl 6 Advent Calendar such a Success?
- What you can write in Perl 6 today
- Why you don't need the Y combinator in Perl 6
- You are good enough!
Sun, 11 Apr 2010
A Perl 6 Date Module
Permanent link
The Perl 6 specification talks, among other things, about built-in date/time classes. After much discussions back and forth it is now (and is likely staying that way) a subset of the excellent Perl 5 module DateTime.
The discussions on the perl6-language mailing list showed that Dave Rolsky, author of DateTime, wants us to learn from the shortcomings of DateTime, in particular having a date-only class looks like a good idea to him.
That encouraged me to implement such a module. There's also prior art for that on CPAN: Date::Simple.
It's really simple, as the name says: You can construct a Date::Simple
object either from year, month, day or from a string in the form
YYYY-MM-DD, subtracting two dates yields an integer, adding or
subtracting an integer to a date gives another date, you can ++
or -- date objects to get the next/previous day, and you can
query date objects for year, month, day and day of week.
With some good
literature at hand (and the Date::Simple test suite for inspiration)
that's rather straight forward to implement, so that's
what I did. I called it Date, and the code is on github.
It works to the extent possible by current Rakudo: all the object oriented features work, overloading operators doesn't quite work yet. Still the logic for the operators is already there, and once the bug in Rakudo is fixed, the Date module will be nearly fully implemented.
I enjoyed doing some solid work in this area of continued bikeshedding, and I'll wait and see if people want such a class in Perl 6 or not.
Comments / Trackbacks:
Trackback URL:
/blog-en/perl-6/date-module.trackback
Chris Dolan wrote
Good enough?
This concerns me. Java learned the hard way that having "good enough" built-in date support is permanently bad because there will be a whole class of bugs that plagues the language forever. The Joda-Time project (that hopefully bring sane date math to Java 1.7) is an example of immutable dates/times/periods/durations done right.
One thing about Perl5's implementation is that the builtin time support was so limited that nobody sane actually tried to use it for real date/time work.
But then, you've got code and I just have words. :-)
Moritz wrote
Good enough?
What gives you the impression that Date is "good enough" and not "good"?
It is meant to be "good", in the sense that for the type of calculations it does it is much easier to use than the full DateTime, which is still available if Date is not enough.
Klamsi wrote
DateTime is a really good module. The big Problem for me to use it in a webserver context ist, that it is REALLY slow.
To query the database server with "SELECT $date - INTERVAL 1 DAY" for example is even much more performant than to calc it per DateTime.
Klamsi wrote
For interest I testet
SELECT BENCHMARK(1000000, "2010-01-01 00:00:00" - INTERVAL cast(rand()*50 as unsigned) DAY);
1 row in set (1.08 sec)
In Perl using DateTime I think it never would finish.
Write a comment
The comments on this blog post have been disabled; the comment form below will not work.