// -*- c++ -*- /* * Jakelib2 - General purpose C++ library * Copyright (C) 2001 Florian Wolff (florian@donuz.de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: CalendarTest.jlc,v 1.9 2003/09/26 15:55:26 florian Exp $ */ #include "Test.h" #include #include using namespace jakelib::lang; using namespace jakelib::util; #pragma javasyntax #ifdef MSVC # define MILLIS_PER_DAY (24L * 60L * 60L * 1000L) #else # define MILLIS_PER_DAY (24LL * 60LL * 60LL * 1000LL) #endif void printDates() { jlong now = System::currentTimeMillis(); for (jlong time = 0; time <= now; time += MILLIS_PER_DAY) { GregorianCalendar cal(time); System::out->println("" .. time .. ": " .. cal.get(Calendar::DAY_OF_MONTH) .. "." .. cal.get(Calendar::MONTH) +1 .. "." .. cal.get(Calendar::YEAR)); } } void calendarTest() { try { Date *now = new Date(); Date *past1 = new Date(0); Date *past2 = new Date(0); System::out->println(`"now = "` .. now); System::out->println(`"past1 = "` .. past1); System::out->println(`"past2 = "` .. past2); System::out->println(`"past1 == past2: "` .. past1->equals(past2)); System::out->println(`"now == past2: "` .. now->equals(past2)); System::out->println(`"now after past2: "` .. now->after(past2)); System::out->println(`"now before past2: "` .. now->before(past2)); System::out->println(`"Default TimeZone: "` .. TimeZone::getDefault()); GregorianCalendar *greg = new GregorianCalendar(); System::out->println(`"GregorianCalendar(): "` .. greg); System::out->println(`"GregorianCalendar()->get(DATE): "` .. greg->get(Calendar::DATE)); System::out->println(`"GregorianCalendar()->get(MONTH): "` .. greg->get(Calendar::MONTH)); System::out->println(`"GregorianCalendar()->get(DAY_OF_WEEK): "` .. greg->get(Calendar::DAY_OF_WEEK)); System::out->println(`"GregorianCalendar()->get(YEAR): "` .. greg->get(Calendar::YEAR)); System::out->println(`"GregorianCalendar()->get(DAY_OF_YEAR): "` .. greg->get(Calendar::DAY_OF_YEAR)); System::out->println(`"GregorianCalendar()->get(DAY_OF_MONTH): "` .. greg->get(Calendar::DAY_OF_MONTH)); System::out->println(`"GregorianCalendar()->get(HOUR): "` .. greg->get(Calendar::HOUR)); System::out->println(`"GregorianCalendar()->get(MINUTE): "` .. greg->get(Calendar::MINUTE)); System::out->println(`"GregorianCalendar()->get(SECOND): "` .. greg->get(Calendar::SECOND)); GregorianCalendar *greg2 = new GregorianCalendar(greg->get(Calendar::YEAR), greg->get(Calendar::MONTH), greg->get(Calendar::DATE), greg->get(Calendar::HOUR), greg->get(Calendar::MINUTE), greg->get(Calendar::SECOND)); System::out->println(`"GregorianCalendar(): "` .. greg2); System::out->println(`"GregorianCalendar()->get(DATE): "` .. greg2->get(Calendar::DATE)); System::out->println(`"GregorianCalendar()->get(MONTH): "` .. greg2->get(Calendar::MONTH)); System::out->println(`"GregorianCalendar()->get(YEAR): "` .. greg2->get(Calendar::YEAR)); System::out->println(`"GregorianCalendar()->get(HOUR): "` .. greg2->get(Calendar::HOUR)); System::out->println(`"GregorianCalendar()->get(MINUTE): "` .. greg2->get(Calendar::MINUTE)); System::out->println(`"GregorianCalendar()->get(SECOND): "` .. greg2->get(Calendar::SECOND)); System::out->println(`"GregorianCalendar()->getTime(): "` .. greg2->getTime()); System::out->println(`"GregorianCalendar()->getTime(): "` .. greg->getTime()); System::out->println(`"System::currentTimeMillis(): "` .. System::currentTimeMillis()); //printDates(); //System::out->println(`"Greg: "` .. GregorianCalendar(1582, 9, 15).getTimeInMillis()); } catch (Exception *ex) { System::out->println(ex); } }