<commit_before>package DateTime;

use strict;

use vars qw($VERSION);

$VERSION = '0.01';

use Carp;
use Date::Leapyear ();
use DateTime::Duration;
use Time::Local ();

# for some reason, overloading doesn't work unless fallback is listed
# early.
use overload 'fallback' => 1,
             '<=>' => 'compare',
             '-' => \&subtract,
             '+' => \&_add_overload;

my( @MonthLengths, @LeapMonthLengths, %AddUnits );

my $LocalZone   = $ENV{TZ} || 0;
my $LocalOffset = _calc_local_offset();

my $DefaultLanguageClass = 'DateTime::Language::English';

sub import {
    my $class = shift;
    my %args = @_;

    if ( $args{language} ) {
        my $module = 'DateTime::Language::' . ucfirst $args{language};

        eval "use $module";
        die $@ if $@;

        $DefaultLanguageClass = $module;
    } else {
        eval "use $DefaultLanguageClass";
        die $@ if $@;
    }
}

sub new {
    my $class = shift;
    my ( $self, %args, $sec, $min, $hour, $day, $month, $year, $tz );

    # $zflag indicates whether or not this time is natively in UTC
    my $zflag = 0;

    # First argument can be a DateTime (or subclass thereof) object
    if ( ref $_[0] ) {
        $args{ical} = $_[0]->ical;
    } else {
        %args = @_;
    }

    $self = {};

    if ( $args{language} ) {
        my $class = 'DateTime::Language::' . ucfirst $args{language};
        $self->{language} = $class->new;
    } else {
        $self->{language} = $DefaultLanguageClass->new;
    }

    # Date is specified as epoch#{{{
    if ( defined( $args{epoch} ) ) {

        ( $sec, $min, $hour, $day, $month, $year ) =
          ( gmtime( $args{epoch} ) )[ 0, 1, 2, 3, 4, 5 ];
        $year += 1900;
        $month++;

        $zflag = 1;    # epoch times are by definition in GMT
    }

    # Date is specified as ical string#{{{
    elsif ( defined( $args{ical} ) ) {

        # Timezone, if any
        $args{ical} =~ s/^(?:TZID=([^:]+):)?//;
        $tz = $1;

        # Split up ical string
        ( $year, $month, $day, $hour, $min, $sec, $zflag ) =
          $args{ical} =~ /^(?:(\d{4})(\d\d)(\d\d))
               (?:T(\d\d)?(\d\d)?(\d\d)?)?
                         (Z)?$/x;

        # TODO: figure out what to do if we get a TZID.  I'd suggest
        # we store it for use by modules that care about TZID
        # names. But we don't want this module to deal with timezone
        # names, only offsets, I think.  --srl
<commit_msg>turn $DefaultLanguageClass into a method (for benefit of possible subclasses)<commit_after>package DateTime;

use strict;

use vars qw($VERSION);

$VERSION = '0.01';

use Carp;
use Date::Leapyear ();
use DateTime::Duration;
use Time::Local ();

# for some reason, overloading doesn't work unless fallback is listed
# early.
use overload 'fallback' => 1,
             '<=>' => 'compare',
             '-' => \&subtract,
             '+' => \&_add_overload;

my( @MonthLengths, @LeapMonthLengths, %AddUnits );

my $LocalZone   = $ENV{TZ} || 0;
my $LocalOffset = _calc_local_offset();

{
    # I'd rather use Class::Data::Inheritable for this, but there's no
    # way to add the module-loading behavior to an accessor it
    # creates, despite what its docs say!
    my $DefaultLanguageClass;
    sub DefaultLanguageClass {
        my $class = shift;

        if (@_) {
            my $lang_class = shift;

            $lang_class = "DateTime::Language::$lang_class"
                unless $lang_class =~ /^DateTime::Language::/;

            eval "use $lang_class";
            die $@ if $@;

            $DefaultLanguageClass = $lang_class;
        }

        return $DefaultLanguageClass;
    }
}
__PACKAGE__->DefaultLanguageClass('English');

sub import {
    my $class = shift;
    my %args = @_;

    $class->DefaultLanguageClass( $args{language} )
        if $args{language};
}

sub new {
    my $class = shift;
    my ( $self, %args, $sec, $min, $hour, $day, $month, $year, $tz );

    # $zflag indicates whether or not this time is natively in UTC
    my $zflag = 0;

    # First argument can be a DateTime (or subclass thereof) object
    if ( ref $_[0] ) {
        $args{ical} = $_[0]->ical;
    } else {
        %args = @_;
    }

    $self = {};

    if ( $args{language} ) {
        my $class = 'DateTime::Language::' . ucfirst $args{language};
        $self->{language} = $class->new;
    } else {
        $self->{language} = $class->DefaultLanguageClass->new;
    }

    # Date is specified as epoch#{{{
    if ( defined( $args{epoch} ) ) {

        ( $sec, $min, $hour, $day, $month, $year ) =
          ( gmtime( $args{epoch} ) )[ 0, 1, 2, 3, 4, 5 ];
        $year += 1900;
        $month++;

        $zflag = 1;    # epoch times are by definition in GMT
    }

    # Date is specified as ical string#{{{
    elsif ( defined( $args{ical} ) ) {

        # Timezone, if any
        $args{ical} =~ s/^(?:TZID=([^:]+):)?//;
        $tz = $1;

        # Split up ical string
        ( $year, $month, $day, $hour, $min, $sec, $zflag ) =
          $args{ical} =~ /^(?:(\d{4})(\d\d)(\d\d))
               (?:T(\d\d)?(\d\d)?(\d\d)?)?
                         (Z)?$/x;

        # TODO: figure out what to do if we get a TZID.  I'd suggest
        # we store it for use by modules that care about TZID
        # names. But we don't want this module to deal with timezone
        # names, only offsets, I think.  --srl

{'fraction_non_alphanumeric': 0.1665424739195231, 'fraction_numerical': 0.00782414307004471, 'mean_word_length': 2.1619552414605416, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5747547', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1778, 'n_words': 523}