Overview

Namespaces

  • Apptus
    • ESales
      • Connector
        • Report
        • Time
    • Util
      • Cache
  • PHP
  • Overview
  • Namespace
  • Class
  • Tree
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 
<?php
namespace Apptus\ESales\Connector\Time;

/**
 * A date on any valid ISO 8601 format.
 */
abstract class IsoDate {
    /**
     * Parses a date on ISO 8601 format and return it.
     *
     * If the date cannot be parsed, throws an exception.
     *
     * @param string
     *          The input string. May not be null.
     * @throws \InvalidArgumentException if the input cannot be parsed.
     * @return IsoDate A date.
     */
    public static function parse($input) {
        if ($input == null) {
            throw new \InvalidArgumentException('Input may not be null.');
        } elseif (!is_string($input)) {
            throw new \InvalidArgumentException('Input must be string.');
        }

        $date = CalendarDate::tryParseAbsolute($input);

        if ($date === null) {
            $date = WeekDate::tryParseAbsolute($input);
        }
        if ($date === null) {
            $date = OrdinalDate::tryParseAbsolute($input);
        }
        if ($date === null) {
            throw new \InvalidArgumentException('Illegal date format. ISO 8601 format is required.');
        }
        return $date;
    }

    /**
     * Parses a date on ISO 8601 format and return it.
     *
     * If the date cannot be parsed, throws an exception.
     *
     * The date may omit the larger units, which in such case will be
     * inherited from the start date supplied. Note that the start date
     * then must be defined in the same date format as the input string.
     *
     * @param string
     *          The input string. May not be null.
     * @param IsoDate
     *          The date to inherit values from if omitted in input.
     * @throws \InvalidArgumentException if the input cannot be parsed.
     * @return IsoDate A date.
     */
    public static function parseInContext($input, IsoDate $start) {
        if ($input === null) {
            throw new \InvalidArgumentException('Input may not be null.');
        } elseif (!is_string($input)) {
            throw new \InvalidArgumentException('Input must be string.');
        }

        if ($input === '') {
            return $start;
        }

        $date = null;

        if ($start instanceof CalendarDate) {
            $date = CalendarDate::tryParseRelative($input, $start);
        } elseif ($start instanceof WeekDate) {
            $date = WeekDate::tryParseRelative($input, $start);
        } elseif ($start instanceof OrdinalDate) {
            $date = OrdinalDate::tryParseRelative($input, $start);
        }

        if ($date === null) {
            throw new \InvalidArgumentException('Illegal date format. ISO 8601 format is required.');
        }

        return $date;
    }

    /**
     * Returns true if this date defines a specific day, false otherwise.
     *
     * @internal
     * @return boolean
     */
    public abstract function hasDayPrecision();

    /**
     * Returns a point in time represented by this date and a supplied time of day.
     *
     * If the date or time lacks precision, or if the time is omitted, then the
     * smallest valid point in time for this specification is used.
     *
     * @param Time
     *          A time of day. May be null.
     * @param \DateTimeZone
     *          The timezone.
     * @return TimePoint A point in time.
    */
    public abstract function toTimePoint(Time $t = null, \DateTimeZone $tz);

    /**
     * Returns a string with an ISO 8601 representation of this date.
     *
     * @return string An ISO 8601 representation of this date.
     */
    public abstract function __toString();
}
Apptus ESales Connector PHP API documentation generated by ApiGen