Exemplo n.º 1
0
            return $this->year == $other->year && $this->month == $other->month;
        }
        return false;
    }
    //-----------------------------------------------------------------------
    /**
     * Outputs this year-month as a {@code String}, such as {@code 2007-12}.
     * <p>
     * The output will be in the format {@code uuuu-MM}:
     *
     * @return string a string representation of this year-month, not null
     */
    public function __toString()
    {
        $absYear = Math::abs($this->year);
        $buf = '';
        if ($absYear < 1000) {
            if ($this->year < 0) {
                $y = (string) ($this->year - 10000);
                $buf .= substr($y, 0, 1) . substr($y, 2);
            } else {
                $buf .= substr($this->year + 10000, 1);
            }
        } else {
            $buf .= $this->year;
        }
        return $buf . ($this->month < 10 ? "-0" : "-") . $this->month;
    }
}
YearMonth::init();