Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

X::Temporal::InvalidFormat

  • Loading branch information...
commit d0b66401235c30b0b3b21f09b1b8d0b04daab6f2 1 parent 452cdbc
Moritz Lenz moritz authored
Showing with 19 additions and 2 deletions.
  1. +10 −0 src/core/Exception.pm
  2. +9 −2 src/core/Temporal.pm
10 src/core/Exception.pm
View
@@ -773,6 +773,16 @@ my class X::HyperOp::NonDWIM is Exception {
}
+my class X::Temporal is Exception { }
+my class X::Temporal::InvalidFormat is X::Temporal {
+ has $.invalid-str;
+ has $.target = 'Date';
+ has $.format;
+ method message() {
+ "Ivalid $.target string '$.invalid-str'; use $.format instead";
+ }
+}
+
{
my %c_ex;
%c_ex{'X::TypeCheck::Binding'} := sub ($got, $expected) is hidden_from_backtrace {
11 src/core/Temporal.pm
View
@@ -254,7 +254,11 @@ my class DateTime does Dateish {
multi method new(Str $format, :$timezone is copy = 0, :&formatter=&default-formatter) {
$format ~~ /^ (\d**4) '-' (\d\d) '-' (\d\d) T (\d\d) ':' (\d\d) ':' (\d\d) (Z || (<[\-\+]>) (\d\d)(\d\d))? $/
- or die 'Invalid DateTime string; please an ISO 8601 timestamp';
+ or X::Temporal::InvalidFormat.new(
+ invalid-str => $format,
+ target => 'DateTime',
+ format => 'an ISO 8601 timestamp (yyyy-mm-ddThh::mm::ssZ or yyyy-mm-ddThh::mm::ss+0100)',
+ ).throw;
my $year = (+$0).Int;
my $month = (+$1).Int;
my $day = (+$2).Int;
@@ -418,7 +422,10 @@ my class Date does Dateish {
multi method new(Str $date) {
$date ~~ /^ \d\d\d\d '-' \d\d '-' \d\d $/
- or die 'Invalid Date string; please use the format "yyyy-mm-dd"';
+ or X::Temporal::InvalidFormat.new(
+ invalid-str => $date,
+ format => 'yyyy-mm-dd',
+ ).throw;
self.new(|$date.split('-').map({.Int}));
}
Please sign in to comment.
Something went wrong with that request. Please try again.