Dallycot
    
    
  
  
  
view release on metacpan or search on metacpan
lib/Dallycot/Library/Core/DateTime.pm view on Meta::CPAN
use experimental qw(switch);
use Carp qw(croak);
use DateTime;
use DateTime::Calendar::Mayan;
use DateTime::Calendar::Hebrew;
use DateTime::Calendar::Julian;
use DateTime::Calendar::Pataphysical;
use DateTime::Calendar::Hijri;
# Hack to get the Islamic calendar convertable
sub DateTime::Calendar::Hijri::clone { $_[0] }
use DateTime::Format::Flexible;
use List::Util qw(all any);
use Promises qw(deferred);
use Dallycot::Library::Core          ();
use Dallycot::Value::DateTime;
lib/Dallycot/Library/Core/DateTime.pm view on Meta::CPAN
    time_zone => 0
  },
);
define
  'date' => (
  hold => 0,
  arity => 1,
  options => {
    timezone => Dallycot::Value::String->new("UTC"),
    calendar => Dallycot::Value::String->new("Gregorian")
  }
  ),
  sub {
  my ( $engine, $options, $vector ) = @_;
  if(!$vector -> isa('Dallycot::Value::Vector')) {
    croak 'The argument for date must be a vector of numerics';
  }
  if(!all { $_ -> isa('Dallycot::Value::Numeric') } $vector->values) {
    croak 'The argument for date must be a vector of numerics';
  }
  my @valid_calendars = grep { defined $CALENDAR_ARGS{$_}{date_names} } keys %CALENDAR_ARGS;
  if(!$options->{calendar}->isa('Dallycot::Value::String')) {
    croak 'The calendar option for date must be one of ' . join(', ', @valid_calendars);
  }
  if(!$options->{timezone}->isa('Dallycot::Value::String') && !$options->{timezone}->isa('Dallycot::Value::Undefined')) {
    croak 'The timezone option for date must be a string or nil';
  }
  my $calendar = $options->{calendar}->value;
  if(!any { $_ eq $calendar } @valid_calendars) {
    croak 'The calendar option for date must be one of ' . join(', ', @valid_calendars);
  }
  my @values = map { $_ -> value -> numify } $vector -> values;
  my @arg_names = @{$CALENDAR_ARGS{$calendar}{date_names}};
  my $class = $CALENDAR_ARGS{$calendar}{class};
  $#arg_names = $#values if $#values < $#arg_names;
  my %args;
  @args{@arg_names} = @values;
  if($options->{timezone}->isa('Dallycot::Value::String') && $CALENDAR_ARGS{$calendar}{time_zone}) {
    $args{time_zone} = $options->{timezone}->value;
  }
  return Dallycot::Value::DateTime -> new(
    object => $class -> new(%args),
    class => $class
  );
};
define
  'calendar-convert' => (
    hold => 0,
    arity => [1,2],
    options => {}
  ), sub {
  my ( $engine, $options, $date, $calendar ) = @_;
  if($calendar && !$calendar->isa('Dallycot::Value::String')) {
    croak 'The calendar argument to calendar-convert must be a string';
  }
  if($calendar) {
    $calendar = $calendar->value;
  }
  else {
    $calendar = 'Gregorian';
  }
  if(!$CALENDAR_ARGS{$calendar}) {
    croak 'Calendar-convert only supports ' . join(', ', sort keys %CALENDAR_ARGS);
  }
  if(!$date -> isa('Dallycot::Value::DateTime')) {
    croak 'Calendar-convert expects a date object as its first argument';
  }
  return Dallycot::Value::DateTime->new(
    object => $date->value,
    class => $CALENDAR_ARGS{$calendar}{class}
  );
};
define
  'duration' => (
  hold => 0,
  arity => [1,2],
  options => {
    calendar => Dallycot::Value::String->new("Gregorian")
    }
  ),
  sub {
  my ( $engine, $options, $vector, $target ) = @_;
  if(defined $target) {
    if(!$vector->isa('Dallycot::Value::DateTime') || !$target->isa('Dallycot::Value::DateTime')) {
      croak 'Both arguments for duration must be dates';
    }
    return Dallycot::Value::Duration->new(
lib/Dallycot/Library/Core/DateTime.pm view on Meta::CPAN
    );
  }
  if(!$vector -> isa('Dallycot::Value::Vector')) {
    croak 'The argument for duration must be a vector of numerics';
  }
  if(!all { $_ -> isa('Dallycot::Value::Numeric') } $vector->values) {
    croak 'The argument for duration must be a vector of numerics';
  }
  my @valid_calendars = grep { defined $CALENDAR_ARGS{$_}{duration_names} } keys %CALENDAR_ARGS;
  if(!$options->{calendar}->isa('Dallycot::Value::String')) {
    croak 'The calendar option for duration must be one of ' . join(', ', @valid_calendars);
  }
  my $calendar = $options->{calendar}->value;
  if(!any { $_ eq $calendar } @valid_calendars) {
    croak 'The calendar option for duration must be one of ' . join(', ', @valid_calendars);
  }
  my @values = map { $_ -> value -> numify } $vector -> values;
  my @arg_names = @{$CALENDAR_ARGS{$calendar}{duration_names}};
  my $class = $CALENDAR_ARGS{$calendar}{class};
  $#arg_names = $#values;
  my %args;
  @args{@arg_names} = @values;
  return Dallycot::Value::Duration -> new(
    %args
  );
};
lib/Dallycot/Parser.pm view on Meta::CPAN
<positiveFloat exponent> ~ [eE] [-+] <integer>
positiveFloatSansExponent ~ <positiveFloat integer part> '.' zero
                          | <positiveFloat integer part> '.' <positiveFloat fractional part>
                          | zero '.' <positiveFloat fractional part>
positiveFloat ~ positiveFloatSansExponent
              | positiveFloatSansExponent <positiveFloat exponent>
              | <positiveFloat integer part> <positiveFloat exponent>
duration ~ 'P' calendarDuration
         | 'P' calendarDuration 'T' clockDuration
         | 'P' 'T' clockDuration
calendarDuration ~ yearDuration monthlyDuration
                 | monthlyDuration
monthlyDuration ~ monthDuration dayDuration
                | dayDuration
yearDuration ~ zero 'Y'
             | positiveInteger 'Y'
monthDuration ~ zero 'M'
              | positiveInteger 'M'
lib/Dallycot/Value/DateTime.pm view on Meta::CPAN
        map { $_ => $options{$_} } grep { $options{$_} } keys %options
      )
    ] => $class;
  }
}
sub to_rdf {
  my($self, $model) = @_;
  # we need to record the date/time as represented in RDF, but might want to
  # record the calendar type as well
  my $literal = RDF::Trine::Node::Literal->new(
    DateTime->from_object(object => $self->[0])->iso8601,
    '',
    $model -> meta_uri('xsd:dateTime')
  );
  return $literal if $self->[0] -> isa('DateTime');
  my $bnode = $model->bnode;
  $model -> add_type($bnode, 'loc:DateTime');
  $model -> add_connection($bnode, 'rdf:value', $literal);
  my $calendar_type = (reverse split(/::/, blessed($self->[0])))[0];
  $model -> add_connection($bnode, 'loc:calendar', $calendar_type);
  if($self->[0]->can('epoch')) {
    $model -> add_connection($bnode, 'loc:epoch', $model->integer(
      $self->[0]->epoch
    ));
  }
  return $bnode;
}
sub now {
lib/Dallycot/Value/DateTime.pm view on Meta::CPAN
}
sub in_timezone {
  my($self, $timezone) = @_;
  my $class = ref $self;
  return bless [ $self -> [0] -> clone -> set_time_zone($timezone) ] => $class;
}
# sub to_calendar {
#   my($self, $calendar_class) = @_;
#
#   my $class = ref $self;
#
#   return bless [ $calendar_class->from_object(object => $self->[0]) ] => $class;
# }
sub as_text {
  my($self) = @_;
  if($self -> [0] -> can('datetime')) {
    return $self -> [0] -> datetime;
  }
  else {
    return $self -> [0] -> date;
lib/Dallycot/Value/Duration.pm view on Meta::CPAN
        map { $_ => $options{$_} } grep { $options{$_} } keys %options
      )
    ] => $class;
  }
}
sub to_rdf {
  my($self, $model) = @_;
  # we need to record the date/time as represented in RDF, but might want to
  # record the calendar type as well
  my $literal = RDF::Trine::Node::Literal->new(
    $self -> as_text,
    '',
    $model -> meta_uri('xsd:duration')
  );
  return $literal;
}
sub as_text {
( run in 0.415 second using v1.01-cache-2.11-cpan-c333fce770f )