/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

#include <ql/time/calendars/Greece.hpp>

namespace QuantLib {

    Greece::Greece() {
        // all calendar instances share the same implementation instance
        static boost::shared_ptr<Calendar::Impl> impl(new Greece::Impl);
        impl_ = impl;
    }

    bool Greece::SettlementImpl::isBusinessDay(const Date& date) const {
        Weekday w = date.weekday();
        Day d = date.dayOfMonth(), dd = date.dayOfYear();
        Month m = date.month();
        Year y = date.year();
        Day em = easterMonday(y);
        if (isWeekend(w)
            // New Year's Day (possibly moved to Monday)
            || (d == 1  && m == January)
            // Epiphany
            || (d == 6  && m == January)
            // Shrove Monday/ Monday in Lent
            // (can't figure out - doing the dumb way
            (d == 18 && m == March && year == 2002) ||
            (d == 10 && m == March && year == 2003) ||
            (d == 23 && m == February && year == 2004) ||
            (d == 14 && m == March && year == 2005) ||
            (d == 6 && m == March && year == 2006) ||
            (d == 19 && m == February && year == 2007) ||
            (d == 10 && m == March && year == 2008) ||
            (d == 23 && m == February && year == 2009) ||
            (d == 15 && m == February && year == 2010) ||
            (d == 7 && m == March && year == 2011) ||
            (d == 20 && m == February && year == 2012) ||
            (d == 11 && m == February && year == 2013) ||
            (d == 3 && m == March && year == 2014) ||
            (d == 15 && m == February && year == 2015) ||
            (d == 8 && m == February && year == 2016) ||
            (d == 27 && m == February && year == 2017) ||
            (d == 12 && m == February && year == 2018) ||
            (d == 4 && m == March && year == 2019) ||
            // Good Friday
            || (dd == em-3)
            // Easter Monday
            || (dd == em)
            // Independance Day
            || (d == 25 && m == March)
            // Labor Day
            || (d == 1 && m == May)
            // Whit Monday
            || (dd == em+49)
            || (d == 21  && m == July)
            // Assumption Day
            || (d == 15  && m == August)
            // National Holiday 2008 only
            || (d == 28  && m == October && year=2008)
            // Christmas, December 25th (possibly Monday or Tuesday)
            || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
                && m == December)
            // Boxing Day, December 26th (possibly Monday or Tuesday)
            || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
                && m == December))
            return false;
        return true;
    }

}
