コード例 #1
0
ファイル: YearMonth.php プロジェクト: brick/date-time
 /**
  * Obtains an instance of `YearMonth` from a text string.
  *
  * @param string              $text   The text to parse, such as `2007-12`.
  * @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser.
  *
  * @return YearMonth
  *
  * @throws DateTimeException      If the date is not valid.
  * @throws DateTimeParseException If the text string does not follow the expected format.
  */
 public static function parse($text, DateTimeParser $parser = null)
 {
     if (!$parser) {
         $parser = IsoParsers::yearMonth();
     }
     return YearMonth::from($parser->parse($text));
 }
コード例 #2
0
ファイル: DateTimeConverter.php プロジェクト: brick/brick
 /**
  * {@inheritdoc}
  */
 public function expand($className, $value, array $options = [])
 {
     try {
         switch ($className) {
             case Duration::class:
                 return Duration::parse($value);
             case LocalDate::class:
                 return LocalDate::parse($value);
             case LocalTime::class:
                 return LocalTime::parse($value);
             case LocalDateTime::class:
                 return LocalDateTime::parse($value);
             case TimeZoneOffset::class:
                 return TimeZoneOffset::parse($value);
             case TimeZoneRegion::class:
                 return TimeZoneRegion::parse($value);
             case YearMonth::class:
                 return YearMonth::parse($value);
             case ZonedDateTime::class:
                 return ZonedDateTime::parse($value);
         }
     } catch (DateTimeParseException $e) {
         throw new ObjectNotConvertibleException($e->getMessage(), $e->getCode(), $e);
     }
     return null;
 }
コード例 #3
0
ファイル: YearMonthTest.php プロジェクト: brick/date-time
 public function testToString()
 {
     $this->assertSame('2013-09', (string) YearMonth::of(2013, 9));
 }
コード例 #4
0
ファイル: LocalDate.php プロジェクト: brick/date-time
 /**
  * Resolves the date, resolving days past the end of month.
  *
  * @param integer $year  The year to represent, validated as an integer from MIN_YEAR to MAX_YEAR.
  * @param integer $month The month-of-year to represent, validated as an integer from 1 to 12.
  * @param integer $day   The day-of-month to represent, validated as an integer from 1 to 31.
  *
  * @return LocalDate
  */
 private function resolvePreviousValid($year, $month, $day)
 {
     if ($day > 28) {
         $day = min($day, YearMonth::of($year, $month)->getLengthOfMonth());
     }
     return new LocalDate($year, $month, $day);
 }
コード例 #5
0
ファイル: Year.php プロジェクト: brick/date-time
 /**
  * Combines this year with a month to create a YearMonth.
  *
  * @param integer $month The month-of-year to use, from 1 to 12.
  *
  * @return YearMonth
  *
  * @throws DateTimeException If the month is invalid.
  */
 public function atMonth($month)
 {
     return YearMonth::of($this->year, $month);
 }
コード例 #6
0
ファイル: AbstractTestCase.php プロジェクト: brick/date-time
 /**
  * @param integer   $year      The expected year.
  * @param integer   $month     The expected month.
  * @param YearMonth $yearMonth The year-month to test.
  */
 protected function assertYearMonthIs($year, $month, YearMonth $yearMonth)
 {
     $this->compare([$year, $month], [$yearMonth->getYear(), $yearMonth->getMonth()]);
 }