Daisuke Maki wrote:
>
> Hi all,
>
> I'm now working on DateTime::Event::SolarTerm which will calculate the
> major and solar terms of the year. I'm currently using the DateTime::Set
> interface to do this:
>
> my $base_time = DateTime->new(...);
> my $major_terms = DateTime::Event::SolarTerm->major_term();
>
> my $next = $major_terms->next($base_time);
> # and previous(), and interator(), etc.
>
> However, I'd like more than just the time and date of the next term to
> be available for the user -- namely, I'd like things like
>
> - name of the term
> - the solar longitude
> - major/minor term
>
> Now, given that the DateTime::Set interface expected next() and
> previous() to return DateTime objects, what's the recommended approach
> to providing more information than just the date/time?
>
> I can think of a couple of ways to do this. One is to return some sort
> of subclass of DateTime. The other is to provide a function that
> converts a DateTime object into some sort of SolarTerm object.
I think the first approach is ok. It can be used like:
my $next = $major_terms->next($base_time);
print $next->ymd, # DateTime method
$next->term_name, # extra methods
$next->solar_longitude;
I'm not familiar with major/minor terms, but I hope this sample
implementation makes sense:
package DateTime::Event::SolarTerm::_data
use base DateTime;
# the following methods are constructors, and they take a DateTime
parameter:
sub next_major_term { ...
sub previous_major_term { ...
sub next_minor_term { ...
sub previous_minor_term { ...
# the following methods take no parameters:
sub term_name { ...
sub solar_longitude { ...
package DateTime::Event::SolarTerm
sub major_term {
# create a set using
DateTime::Event::SolarTerm::_data::next_major_term / previous_major_term
}
sub minor_term {
# create a set using
DateTime::Event::SolarTerm::_data::next_minor_term / previous_minor_term
}
- Flavio S. Glock