### ----------------------------------------------------
### -- Red
### -- Licenses: Artistic-2.0
### -- Authors: Fernando Correa de Oliveira
### -- File: t/62-date-coercion.rakutest
### ----------------------------------------------------
#!/usr/bin/env raku

use Test;

use Red;

my DateTime $now = "1981-05-21T06:00:00".DateTime;

my $*RED-FALLBACK       = $_ with %*ENV<RED_FALLBACK>;
my $*RED-DEBUG          = $_ with %*ENV<RED_DEBUG>;
my $*RED-DEBUG-RESPONSE = $_ with %*ENV<RED_DEBUG_RESPONSE>;
my $*RED-DEBUG-AST      = $_ with %*ENV<RED_DEBUG_AST>;
my @conf                = (%*ENV<RED_DATABASE> // "SQLite").split(" ");
my $driver              = @conf.shift;
my $*RED-DB             = database $driver, |%( @conf.map: { do given .split: "=" { .[0] => val .[1] } } );

model Foo {
	has Int  $.id is serial;
	has DateTime $.foo-date is column = $now;
}

schema(Foo).drop.create;

Foo.^create;

my Str $today = $now.Date.Str;
ok Foo.^all.grep(*.foo-date.yyyy-mm-dd eq $today).elems, "explicit .yyyy-mm-dd";
ok Foo.^all.grep(*.foo-date eq $now.Date).elems, "eq with Date RHS";
ok Foo.^all.grep(*.foo-date == $now.Date).elems, "== with Date RHS";

done-testing;


