<?php
namespace nur\data\types;

use nur\b\ValueException;
use nur\t\TestCase;

class SDateTypeTest extends TestCase {
  function test() {
    $type = new SDateType();
    $year = date("Y");

    self::assertSame(null, $type->with(null));
    self::assertSame(false, $type->with(false));
    self::assertSame(null, $type->with(""));
    self::assertException(ValueException::class, [$type, "with"], "15");
    self::assertSame("15/01/$year", $type->with("15/1"));
    self::assertSame("15/01/1999", $type->with("15/1/99"));
    self::assertSame("15/01/2020", $type->with("15/1/20"));
    self::assertSame("15/01/2069", $type->with("15/1/69"));
    self::assertSame("15/01/1970", $type->with("15/1/70"));
    self::assertSame("15/01/1971", $type->with("15/1/71"));

    self::assertSame("15/12/2000", $type->with("15/0/2001"));
    self::assertSame("15/01/2002", $type->with("15/13/2001"));
    self::assertSame("31/05/2001", $type->with("0/6/2001"));
    self::assertSame("01/07/2001", $type->with("31/6/2001"));

    self::assertSame("12/03/2020", $type->with(" 12/03/2020 "));
    self::assertException(ValueException::class, [$type, "with"], " 12/03/2020 0");
    self::assertSame("12/03/2020", $type->with(" 12/03/2020 0:0"));
    self::assertSame("12/03/2020", $type->with(" 12/03/2020 0:0:0"));

    self::assertSame("15/01/$year", $type->with("1501"));
    self::assertSame("15/01/1999", $type->with("150199"));
    self::assertSame("15/01/1999", $type->with("15011999"));

    self::assertSame("15/01/1999", $type->with("1999-01-15"));
    self::assertSame("15/01/1999", $type->with("1999-01-15 00:00:00"));
  }
}
