void PayoffBase::initialize(const TimeGrid& timeGrid, const Calendar& calendar){
			
		Date today = Settings::instance().evaluationDate();
		Date issueDate = Date(27,Sep,2012);

		payoffDatesPosition_ = calendar.businessDaysBetween(issueDate,payoffDate_,true,false);
}
Example #2
0
int32_t RelativeDateFormat::dayDifference(Calendar &cal, UErrorCode &status) {
    if(U_FAILURE(status)) {
        return 0;
    }
    // TODO: Cache the nowCal to avoid heap allocs? Would be difficult, don't know the calendar type
    Calendar *nowCal = cal.clone();
    nowCal->setTime(Calendar::getNow(), status);

    // For the day difference, we are interested in the difference in the (modified) julian day number
    // which is midnight to midnight.  Using fieldDifference() is NOT correct here, because
    // 6pm Jan 4th  to 10am Jan 5th should be considered "tomorrow".
    int32_t dayDiff = cal.get(UCAL_JULIAN_DAY, status) - nowCal->get(UCAL_JULIAN_DAY, status);

    delete nowCal;
    return dayDiff;
}
Example #3
0
void
IntlCalendarTest::TestTypes()
{
  Calendar *c = NULL;
  UErrorCode status = U_ZERO_ERROR;
  int j;
  const char *locs [40] = { "en_US_VALLEYGIRL",     
                            "en_US_VALLEYGIRL@collation=phonebook;calendar=japanese",
                            "en_US_VALLEYGIRL@collation=phonebook;calendar=gregorian",
                            "ja_JP@calendar=japanese",   
                            "th_TH@calendar=buddhist", 
                            "ja_JP_TRADITIONAL",   
                            "th_TH_TRADITIONAL", 
                            "th_TH_TRADITIONAL@calendar=gregorian", 
                            "en_US",
                            "th_TH",    // Default calendar for th_TH is buddhist
                            "th",       // th's default region is TH and buddhist is used as default for TH
                            "en_TH",    // Default calendar for any locales with region TH is buddhist
                            NULL };
  const char *types[40] = { "gregorian", 
                            "japanese",
                            "gregorian",
                            "japanese",
                            "buddhist",
                            "japanese",
                            "buddhist",           
                            "gregorian",
                            "gregorian",
                            "buddhist",           
                            "buddhist",           
                            "buddhist",           
                            NULL };

  for(j=0;locs[j];j++) {
    logln(UnicodeString("Creating calendar of locale ")  + locs[j]);
    status = U_ZERO_ERROR;
    c = Calendar::createInstance(locs[j], status);
    CHECK(status, "creating '" + UnicodeString(locs[j]) + "' calendar");
    if(U_SUCCESS(status)) {
      logln(UnicodeString(" type is ") + c->getType());
      if(strcmp(c->getType(), types[j])) {
        dataerrln(UnicodeString(locs[j]) + UnicodeString("Calendar type ") + c->getType() + " instead of " + types[j]);
      }
    }
    delete c;
  }
}
Example #4
0
Incidence *DndFactory::pasteIncidence( const QDate &newDate, const QTime *newTime )
{
  QClipboard *cb = QApplication::clipboard();
  Calendar *cal = createDropCalendar( cb->mimeData() );

  if ( !cal ) {
    kDebug() << "Can't parse clipboard";
    return 0;
  }

  Incidence::List incList = cal->incidences();
  Incidence *inc = incList.isEmpty() ? 0 : incList.first();

  Incidence *newInc = d->pasteIncidence( inc, newDate, newTime );
  newInc->setRelatedTo( 0 );
  return newInc;
}
Example #5
0
void Cmd_AddMaster(const char* args, bool &)
{
	const char *colon = strchr(args, ':');
	std::string ip = GetIP(args);
	short port = GetPort(args, QW_DEFAULT_MASTER_SERVER_PORT);

	cal.ScheduleMasterScan(Clock::get()->GetAppTime(), ip.c_str(), port);
}
Example #6
0
void
CalendarLimitTest::TestCalendarExtremeLimit()
{
    UErrorCode status = U_ZERO_ERROR;
    Calendar *cal = Calendar::createInstance(status);
    if (failure(status, "Calendar::createInstance", TRUE)) return;
    cal->adoptTimeZone(TimeZone::createTimeZone("GMT"));
    DateFormat *fmt = DateFormat::createDateTimeInstance();
    if(!fmt || !cal) {
       dataerrln("can't open cal and/or fmt");
       return;
    }
    fmt->adoptCalendar(cal);
    ((SimpleDateFormat*) fmt)->applyPattern("HH:mm:ss.SSS Z, EEEE, MMMM d, yyyy G");


    // This test used to test the algorithmic limits of the dates that
    // GregorianCalendar could handle.  However, the algorithm has
    // been rewritten completely since then and the prior limits no
    // longer apply.  Instead, we now do basic round-trip testing of
    // some extreme (but still manageable) dates.
    UDate m;
    logln("checking 1e16..1e17");
    for ( m = 1e16; m < 1e17; m *= 1.1) {
        test(m, cal, fmt);
    }
    logln("checking -1e14..-1e15");
    for ( m = -1e14; m > -1e15; m *= 1.1) {
        test(m, cal, fmt);
    }

    // This is 2^52 - 1, the largest allowable mantissa with a 0
    // exponent in a 64-bit double
    UDate VERY_EARLY_MILLIS = - 4503599627370495.0;
    UDate VERY_LATE_MILLIS  =   4503599627370495.0;

    // I am removing the previousDouble and nextDouble calls below for
    // two reasons: 1. As part of jitterbug 986, I am deprecating
    // these methods and removing calls to them.  2. This test is a
    // non-critical boundary behavior test.
    test(VERY_EARLY_MILLIS, cal, fmt);
    //test(previousDouble(VERY_EARLY_MILLIS), cal, fmt);
    test(VERY_LATE_MILLIS, cal, fmt);
    //test(nextDouble(VERY_LATE_MILLIS), cal, fmt);
    delete fmt;
}
Example #7
0
/**
 * j32 {JDK Bug 4210209 4209272}
 * DateFormat cannot parse Feb 29 2000 when setLenient(false)
 */
void
DateFormatRegressionTest::Test4210209(void) {
    UErrorCode status = U_ZERO_ERROR;
    UnicodeString pattern("MMM d, yyyy");
    SimpleDateFormat sfmt(pattern, Locale::getUS(), status);
    SimpleDateFormat sdisp("MMM dd yyyy GG", Locale::getUS(), status);
    DateFormat& fmt = *(DateFormat*)&sfmt; // Yuck: See j25
    DateFormat& disp = *(DateFormat*)&sdisp; // Yuck: See j25
    if (U_FAILURE(status)) {
        dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status));
        return;
    }
    Calendar* calx = (Calendar*)fmt.getCalendar(); // cast away const!
    calx->setLenient(FALSE);
    UDate d = date(2000-1900, UCAL_FEBRUARY, 29);
    UnicodeString s, ss;
    fmt.format(d, s);
    logln(disp.format(d, ss.remove()) + " f> " + pattern +
          " => \"" + s + "\"");
    ParsePosition pos(0);
    d = fmt.parse(s, pos);
    logln(UnicodeString("\"") + s + "\" p> " + pattern +
          " => " + disp.format(d, ss.remove()));
    logln(UnicodeString("Parse pos = ") + pos.getIndex() +
          ", error pos = " + pos.getErrorIndex());
    if (pos.getErrorIndex() != -1) {
        errln(UnicodeString("FAIL: Error index should be -1"));
    }

    // The underlying bug is in GregorianCalendar.  If the following lines
    // succeed, the bug is fixed.  If the bug isn't fixed, they will throw
    // an exception.
    GregorianCalendar cal(status);
    if (U_FAILURE(status)) {
        errln("FAIL: Unable to create Calendar");
        return;
    }
    cal.clear();
    cal.setLenient(FALSE);
    cal.set(2000, UCAL_FEBRUARY, 29); // This should work!
    logln(UnicodeString("Attempt to set Calendar to Feb 29 2000: ") +
                        disp.format(cal.getTime(status), ss.remove()));
    if (U_FAILURE(status)) {
        errln("FAIL: Unable to set Calendar to Feb 29 2000");
    }
}
Example #8
0
//----------------------------------------------------------------------
void
DateFormat::setCalendar(const Calendar& newCalendar)
{
    Calendar* newCalClone = newCalendar.clone();
    if (newCalClone != NULL) {
        adoptCalendar(newCalClone);
    }
}
Example #9
0
int32_t
Calendar::getActualMaximum(UCalendarDateFields field, UErrorCode& status) const
{
    int32_t fieldValue = getLeastMaximum(field);
    int32_t endValue = getMaximum(field);

    // if we know that the maximum value is always the same, just return it
    if (fieldValue == endValue) {
        return fieldValue;
    }

    // clone the calendar so we don't mess with the real one, and set it to
    // accept anything for the field values
    Calendar *work = (Calendar*)this->clone();
    work->setLenient(TRUE);

    // if we're counting weeks, set the day of the week to Sunday.  We know the
    // last week of a month or year will contain the first day of the week.
    if (field == UCAL_WEEK_OF_YEAR || field == UCAL_WEEK_OF_MONTH)
        work->set(UCAL_DAY_OF_WEEK, fFirstDayOfWeek);

    // now try each value from getLeastMaximum() to getMaximum() one by one until
    // we get a value that normalizes to another value.  The last value that
    // normalizes to itself is the actual maximum for the current date
    int32_t result = fieldValue;

    do {
        work->set(field, fieldValue);
        if(work->get(field, status) != fieldValue) {
            break;
        } 
        else {
            result = fieldValue;
            fieldValue++;
        }
    } while (fieldValue <= endValue);

    delete work;

    /* Test for buffer overflows */
    if(U_FAILURE(status)) {
        return 0;
    }

    return result;
}
Example #10
0
// Utility methods to create a date.  This is useful for converting Java constructs
// which create a Date object.
UDate
CalendarTimeZoneTest::date(int32_t y, int32_t m, int32_t d, int32_t hr, int32_t min, int32_t sec)
{
    Calendar* cal = getCalendar();
    if (cal == 0) return 0.0;
    cal->clear();
    cal->set(1900 + y, m, d, hr, min, sec); // Add 1900 to follow java.util.Date protocol
    UErrorCode status = U_ZERO_ERROR;
    UDate dt = cal->getTime(status);
    releaseCalendar(cal);
    if (U_FAILURE(status))
    {
        errln("FAIL: Calendar::getTime failed: %s", u_errorName(status));
        return 0.0;
    }
    return dt;
}
Example #11
0
UBool
Calendar::operator==(const Calendar& that) const
{
    UErrorCode status = U_ZERO_ERROR;
    return isEquivalentTo(that) &&
        getTimeInMillis(status) == that.getTimeInMillis(status) &&
        U_SUCCESS(status);
}
Example #12
0
void TizenSystem::getTimeAndDate(TimeDate &td) const {
	DateTime currentTime;

	if (E_SUCCESS == SystemTime::GetCurrentTime(WALL_TIME, currentTime)) {
		td.tm_sec = currentTime.GetSecond();
		td.tm_min = currentTime.GetMinute();
		td.tm_hour = currentTime.GetHour();
		td.tm_mday = currentTime.GetDay();
		td.tm_mon = currentTime.GetMonth();
		td.tm_year = currentTime.GetYear();

		Calendar *calendar = Calendar::CreateInstanceN(CALENDAR_GREGORIAN);
		calendar->SetTime(currentTime);
		td.tm_wday = calendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK) - 1;
		delete calendar;
	}
}
void iCalConverter::setSource(Calendar& inputCalendar) {
    if(calendar)
        delete calendar;
    calendar = (Calendar *)inputCalendar.clone();
    if(iCalendar) {
        delete [] iCalendar; iCalendar = NULL;
    }
}
/**
 * Verify that TaiWanCalendar shifts years to Minguo Era but otherwise
 * behaves like GregorianCalendar.
 */
void IntlCalendarTest::TestTaiwan() {
    // MG 1 == 1912 AD
    UDate timeA = Calendar::getNow();
    
    // TODO port these to the data items
    int32_t data[] = {
        1,           // B. era   [928479600000]
        1,        // B. year
        1912,        // G. year
        UCAL_JUNE,   // month
        4,           // day

        1,           // B. era   [-79204842000000]
        3,           // B. year
        1914,        // G. year
        UCAL_FEBRUARY, // month
        12,          // day

        1,           // B. era   [-79204842000000]
        96,           // B. year
        2007,        // G. year
        UCAL_FEBRUARY, // month
        12,          // day

        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1
    };
    Calendar *cal;
    UErrorCode status = U_ZERO_ERROR;
    cal = Calendar::createInstance("en_US@calendar=roc", status);
    CHECK(status, UnicodeString("Creating en_US@calendar=roc calendar"));

    // Sanity check the calendar 
    UDate timeB = Calendar::getNow();
    UDate timeCal = cal->getTime(status);

    if(!(timeA <= timeCal) || !(timeCal <= timeB)) {
      errln((UnicodeString)"Error: Calendar time " + timeCal +
            " is not within sampled times [" + timeA + " to " + timeB + "]!");
    }
    // end sanity check


    quasiGregorianTest(*cal,Locale("en_US"),data);
    delete cal;
}
Example #15
0
/**
 * @bug 4071441
 */
void DateFormatRegressionTest::Test4071441(void) 
{
    DateFormat *fmtA = DateFormat::createInstance();
    DateFormat *fmtB = DateFormat::createInstance();

    if (fmtA == NULL || fmtB == NULL){
        dataerrln("Error calling DateFormat::createInstance");
        delete fmtA;
        delete fmtB;
        return;
    }

    // {sfb} Is it OK to cast away const here?
    Calendar *calA = (Calendar*) fmtA->getCalendar();
    Calendar *calB = (Calendar*) fmtB->getCalendar();
    if(!calA || !calB) {
      errln("Couldn't get proper calendars, exiting");
      delete fmtA;
      delete fmtB;
      return;
    }
    UDate epoch = date(0, 0, 0);
    UDate xmas = date(61, UCAL_DECEMBER, 25);

    UErrorCode status = U_ZERO_ERROR;
    calA->setTime(epoch, status);
    failure(status, "calA->setTime");
    calB->setTime(epoch, status);
    failure(status, "calB->setTime");
    if (*calA != *calB)
        errln("Fail: Can't complete test; Calendar instances unequal");
    if (*fmtA != *fmtB)
        errln("Fail: DateFormat unequal when Calendars equal");
    calB->setTime(xmas, status);
    failure(status, "calB->setTime");
    if (*calA == *calB)
        errln("Fail: Can't complete test; Calendar instances equal");
    if (*fmtA != *fmtB)
        errln("Fail: DateFormat unequal when Calendars equivalent");

    logln("DateFormat.equals ok");

    delete fmtA;
    delete fmtB;
}
Example #16
0
UBool 
Calendar::isEquivalentTo(const Calendar& other) const
{
    return getDynamicClassID() == other.getDynamicClassID() &&
        fLenient                == other.fLenient &&
        fFirstDayOfWeek         == other.fFirstDayOfWeek &&
        fMinimalDaysInFirstWeek == other.fMinimalDaysInFirstWeek &&
        *fZone                  == *other.fZone;
}
/**
 * Verify that BuddhistCalendar shifts years to Buddhist Era but otherwise
 * behaves like GregorianCalendar.
 */
void IntlCalendarTest::TestBuddhist() {
    // BE 2542 == 1999 CE
    UDate timeA = Calendar::getNow();

    int32_t data[] = {
        0,           // B. era   [928479600000]
        2542,        // B. year
        1999,        // G. year
        UCAL_JUNE,   // month
        4,           // day

        0,           // B. era   [-79204842000000]
        3,           // B. year
        -540,        // G. year
        UCAL_FEBRUARY, // month
        12,          // day

        0,           // test month calculation:  4795 BE = 4252 AD is a leap year, but 4795 AD is not.
        4795,        // BE [72018057600000]
        4252,        // AD
        UCAL_FEBRUARY,
        29,

        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1
    };
    Calendar *cal;
    UErrorCode status = U_ZERO_ERROR;
    cal = Calendar::createInstance("th_TH@calendar=buddhist", status);
    CHECK(status, UnicodeString("Creating th_TH@calendar=buddhist calendar"));

    // Sanity check the calendar 
    UDate timeB = Calendar::getNow();
    UDate timeCal = cal->getTime(status);

    if(!(timeA <= timeCal) || !(timeCal <= timeB)) {
      errln((UnicodeString)"Error: Calendar time " + timeCal +
            " is not within sampled times [" + timeA + " to " + timeB + "]!");
    }
    // end sanity check


    quasiGregorianTest(*cal,Locale("th_TH@calendar=gregorian"),data);
    delete cal;
}
Example #18
0
static bool test_bond_schedule_anotherday_cython()
{

  Date              last_month;
  Date              today;
  FixedRateBond*    bond;
  Calendar          calendar;
  Date              s_date;
  Date              b_date;
  Date              e_date;
  
  last_month = Date(30, August, 2011);

  today = Date::endOfMonth(last_month);

  bond = get_bond_for_evaluation_date(today);

  calendar = TARGET();

  s_date = calendar.advance(today, 3, Days, Following, 0);

  b_date = bond->settlementDate();

  e_date = QL::get_evaluation_date();

  if (s_date != b_date) {
      std::cout << "Dates are not equivalent " 
           << s_date 
           << " vs " 
           << b_date 
           << std::endl;
      return false;
   }
  
   if (today != e_date) {
      std::cout << "Evaluation dates are not equivalent " 
           << today 
           << " vs " 
           << e_date 
           << std::endl;
      return false;
  }
   return true;
} 
Example #19
0
    void test_remove_event(){
        Calendar<Gregorian> cal;
        cal.set_date(2024,5,12);
        cal.add_event("aa");
        cal.add_event("aa",12,5,2024,20,00,1);
        cal.add_event("ab",13);
        cal.add_event("ac",20,6);
        cal.add_event("aa",3,8,2030,23,59,60*25);

        mod_Stripper<Gregorian> stripperTest;
        stripperTest << cal;
        stringstream ss;
        ss << stripperTest;
        std::string test_string = ss.str();

        TS_ASSERT_DIFFERS(test_string.find("2405121300"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405121700"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("aa"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405122000"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405122001"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("aa"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405131300"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405131700"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("ab"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2406201300"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2406201700"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("ac"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("3008032359"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("3008050059"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("aa"),std::string::npos);

        cal.remove_event("aa");
        mod_Stripper<Gregorian> stripperTest2;
        stripperTest2 << cal;
        stringstream ss2;
        ss2 << stripperTest2;
        test_string = ss2.str();

        TS_ASSERT_EQUALS(test_string.find("2405121300"),std::string::npos);
        TS_ASSERT_EQUALS(test_string.find("2405121700"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405122000"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405122001"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("aa"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405131300"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2405131700"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("ab"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2406201300"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("2406201700"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("ac"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("3008032359"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("3008050059"),std::string::npos);
        TS_ASSERT_DIFFERS(test_string.find("aa"),std::string::npos);

    }
Example #20
0
void CalendarCaseTest::Coptic() {
    static const TestCase tests[] = {
        //      JD Era  Year  Month  Day WkDay  Hour Min Sec
        {2401442.5,  1,  1579,    2,  20,  WED,    0,  0,  0}, // Gregorian: 20/10/1862
        {2402422.5,  1,  1581,   10,  29,  WED,    0,  0,  0}, // Gregorian: 05/07/1865
        {2402630.5,  1,  1582,    5,  22,  MON,    0,  0,  0}, // Gregorian: 29/01/1866
        {2402708.5,  1,  1582,    8,  10,  TUE,    0,  0,  0}, // Gregorian: 17/04/1866
        {2402971.5,  1,  1583,    4,  28,  SAT,    0,  0,  0}, // Gregorian: 05/01/1867
        {2403344.5,  1,  1584,    5,   5,  MON,    0,  0,  0}, // Gregorian: 13/01/1868
        {1721059.5,  0,   285,    5,   7,  SAT,    0,  0,  0}, // Gregorian: 01/01/0000
        {1721425.5,  0,   284,    5,   8,  MON,    0,  0,  0}, // Gregorian: 01/01/0001
        {1824663.5,  0,     2,   13,   6,  WED,    0,  0,  0}, // Gregorian: 29/08/0283
        {1824664.5,  0,     1,    1,   1,  THU,    0,  0,  0}, // Gregorian: 30/08/0283
        {1825029.5,  1,     1,    1,   1,  FRI,    0,  0,  0}, // Gregorian: 29/08/0284
        {1825394.5,  1,     2,    1,   1,  SAT,    0,  0,  0}, // Gregorian: 29/08/0285
        {1825759.5,  1,     3,    1,   1,  SUN,    0,  0,  0}, // Gregorian: 29/08/0286
        {1826125.5,  1,     4,    1,   1,  TUE,    0,  0,  0}, // Gregorian: 30/08/0287
        {1825028.5,  0,     1,   13,   5,  THU,    0,  0,  0}, // Gregorian: 28/08/0284
        {1825393.5,  1,     1,   13,   5,  FRI,    0,  0,  0}, // Gregorian: 28/08/0285
        {1825758.5,  1,     2,   13,   5,  SAT,    0,  0,  0}, // Gregorian: 28/08/0286
        {1826123.5,  1,     3,   13,   5,  SUN,    0,  0,  0}, // Gregorian: 28/08/0287
        {1826124.5,  1,     3,   13,   6,  MON,    0,  0,  0}, // Gregorian: 29/08/0287
          // above is first coptic leap year
        {1826489.5,  1,     4,   13,   5,  TUE,    0,  0,  0}, // Gregorian: 28/08/0288
        {2299158.5,  1,  1299,    2,   6,  WED,    0,  0,  0}, // Gregorian: 13/10/1582
        {2299159.5,  1,  1299,    2,   7,  THU,    0,  0,  0}, // Gregorian: 14/10/1582
        {2299160.5,  1,  1299,    2,   8,  FRI,    0,  0,  0}, // Gregorian: 15/10/1582
        {2299161.5,  1,  1299,    2,   9,  SAT,    0,  0,  0}, // Gregorian: 16/10/1582

        {2415020.5,  1,  1616,    4,  23,  MON,    0,  0,  0}, // Gregorian: 01/01/1900
        {2453371.5,  1,  1721,    4,  23,  SAT,    0,  0,  0}, // Gregorian: 01/01/2005
        {2555528.5,  1,  2000,   13,   5,  FRI,    0,  0,  0}, // Gregorian: 12/09/2284
        {       -1, -1,    -1,   -1,  -1,   -1,   -1, -1, -1}
    };

    UErrorCode status = U_ZERO_ERROR;
    Calendar *c = Calendar::createInstance("cop_EG@calendar=coptic", status);
    if (failure(status, "Calendar::createInstance", TRUE)) return;

    c->setLenient(TRUE);
    doTestCases(tests, c);

    delete c;
}
/**
 * Verify that JapaneseCalendar shifts years to Japanese Eras but otherwise
 * behaves like GregorianCalendar.
 */
void IntlCalendarTest::TestJapanese() {
    UDate timeA = Calendar::getNow();
    
    /* Sorry.. japancal.h is private! */
#define JapaneseCalendar_MEIJI  232
#define JapaneseCalendar_TAISHO 233
#define JapaneseCalendar_SHOWA  234
#define JapaneseCalendar_HEISEI 235
    
    // BE 2542 == 1999 CE
    int32_t data[] = { 
        //       Jera         Jyr  Gyear   m             d
        JapaneseCalendar_MEIJI, 1, 1868, UCAL_SEPTEMBER, 8,
        JapaneseCalendar_MEIJI, 1, 1868, UCAL_SEPTEMBER, 9,
        JapaneseCalendar_MEIJI, 2, 1869, UCAL_JUNE, 4,
        JapaneseCalendar_MEIJI, 45, 1912, UCAL_JULY, 29,
        JapaneseCalendar_TAISHO, 1, 1912, UCAL_JULY, 30,
        JapaneseCalendar_TAISHO, 1, 1912, UCAL_AUGUST, 1,
        
        // new tests (not in java)
        JapaneseCalendar_SHOWA,     64,   1989,  UCAL_JANUARY, 7,  // Test current era transition (different code path than others)
        JapaneseCalendar_HEISEI,    1,   1989,  UCAL_JANUARY, 8,   
        JapaneseCalendar_HEISEI,    1,   1989,  UCAL_JANUARY, 9,
        JapaneseCalendar_HEISEI,    1,   1989,  UCAL_DECEMBER, 20,
        JapaneseCalendar_HEISEI,  15,  2003,  UCAL_MAY, 22,
        -1,-1,-1,-1,-1,-1,-1,-1,-1,-1
    };
    
    Calendar *cal;
    UErrorCode status = U_ZERO_ERROR;
    cal = Calendar::createInstance("ja_JP@calendar=japanese", status);
    CHECK(status, UnicodeString("Creating ja_JP@calendar=japanese calendar"));
    // Sanity check the calendar 
    UDate timeB = Calendar::getNow();
    UDate timeCal = cal->getTime(status);

    if(!(timeA <= timeCal) || !(timeCal <= timeB)) {
      errln((UnicodeString)"Error: Calendar time " + timeCal +
            " is not within sampled times [" + timeA + " to " + timeB + "]!");
    }
    // end sanity check
    quasiGregorianTest(*cal,Locale("ja_JP"),data);
    delete cal;
}
std::string GlobalizationNDK::getFirstDayOfWeek()
{
    UErrorCode status = U_ZERO_ERROR;
    Calendar* cal = Calendar::createInstance(status);
    if (!cal) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::getFirstDayOfWeek: failed to create Calendar instance: %d",
                status);
        return errorInJson(UNKNOWN_ERROR, "Failed to create Calendar instance!");
    }

    UCalendarDaysOfWeek d = cal->getFirstDayOfWeek(status);
    if (status != U_ZERO_ERROR && status != U_ERROR_WARNING_START) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::getFirstDayOfWeek: failed to call getFirstDayOfWeek: %d",
                status);
        return errorInJson(UNKNOWN_ERROR, "Failed to call getFirstDayOfWeek!");
    }

    return resultInJson(d);
}
QModelIndex CalendarItemModel::index( const Calendar *calendar, int column ) const
{
    if ( m_project == 0 || calendar == 0 ) {
        return QModelIndex();
    }
    Calendar *a = const_cast<Calendar*>(calendar);
    int row = -1;
    Calendar *par = a->parentCal();
    if ( par == 0 ) {
         row = m_project->calendars().indexOf( a );
    } else {
        row = par->indexOf( a );
    }
    if ( row == -1 ) {
        return QModelIndex();
    }
    return createIndex( row, column, a );

}
Example #24
0
static void replaceFieldTypesExample() {
		// Use repalceFieldTypes API to replace zone 'zzzz' with 'vvvv'
       u_printf("========================================================================\n");
       u_printf(" replaceFieldTypeExample()\n");
       u_printf("\n");
       u_printf(" Use replaceFieldTypes API to replace zone 'zzzz' with 'vvvv'\n");
       u_printf("========================================================================\n");
	   //! [replaceFieldTypesExample]
		UFILE *out = u_finit(stdout, NULL, "UTF-8");
		UErrorCode status =U_ZERO_ERROR;
		UnicodeString pattern,dateReturned;
		Locale locale =Locale::getFrance();
		Calendar *cal = Calendar::createInstance(status);
		cal->set (1999,9,13,23,58,59);
		UDate date = cal->getTime(status);
		TimeZone *zone = TimeZone::createTimeZone(UnicodeString("Europe/Paris"));
		DateTimePatternGenerator *dtfg = DateTimePatternGenerator::createInstance(locale,status);
	    SimpleDateFormat *sdf = new SimpleDateFormat("EEEE d MMMM y HH:mm:ss zzzz",locale,status);
		sdf->setTimeZone(*zone);
		pattern = sdf->toPattern(pattern);
		u_fprintf(out, "%S\n", UnicodeString("Pattern before replacement:").getTerminatedBuffer());
      	u_fprintf(out, "%S\n", pattern.getTerminatedBuffer());
		dateReturned.remove();
		dateReturned = sdf->format(date, dateReturned, status);
		u_fprintf(out, "%S\n", UnicodeString("Date/Time format in fr_FR:").getTerminatedBuffer());
		u_fprintf(out, "%S\n", dateReturned.getTerminatedBuffer());
        // Replace zone "zzzz" in the pattern with "vvvv"
		UnicodeString newPattern = dtfg->replaceFieldTypes(pattern, "vvvv", status);
		// Apply the new pattern
		sdf->applyPattern(newPattern);
		dateReturned.remove();
		dateReturned = sdf->format(date, dateReturned, status);
		u_fprintf(out, "%S\n", UnicodeString("Pattern after replacement:").getTerminatedBuffer());
     	u_fprintf(out, "%S\n", newPattern.getTerminatedBuffer());
     	u_fprintf(out, "%S\n", UnicodeString("Date/Time format in fr_FR:").getTerminatedBuffer());
		u_fprintf(out, "%S\n", dateReturned.getTerminatedBuffer());
		delete sdf;
		delete dtfg;
		delete zone;
		delete cal;
		u_fclose(out);
	//! [replaceFieldTypesExample]
    }
Example #25
0
void IntlCalendarTest::TestPersian() {
    UDate timeA = Calendar::getNow();
    
    Calendar *cal;
    UErrorCode status = U_ZERO_ERROR;
    cal = Calendar::createInstance("fa_IR@calendar=persian", status);
    CHECK(status, UnicodeString("Creating fa_IR@calendar=persian calendar"));
    // Sanity check the calendar 
    UDate timeB = Calendar::getNow();
    UDate timeCal = cal->getTime(status);

    if(!(timeA <= timeCal) || !(timeCal <= timeB)) {
      errln((UnicodeString)"Error: Calendar time " + timeCal +
            " is not within sampled times [" + timeA + " to " + timeB + "]!");
    }
    // end sanity check
// quasiGregorianTest(*cal,Locale("ja_JP"),data);
    delete cal;
}
Example #26
0
void Cmd_AddPingURL(const char* args, bool &)
{
	if (*args && strstarts(args, "http://")) {
		printf("Adding ping url %s\n", args);
		cal.AddPingUrl(args, Clock::get()->GetAppTime());
	}
	else {
		printf("Usage: addpingurl http://...");
	}
}
Example #27
0
Incidence::List DndFactory::pasteIncidences( const QDate &newDate,
                                             const QTime *newTime )
{
  QClipboard *cb = QApplication::clipboard();
  Calendar *cal = createDropCalendar( cb->mimeData() );
  Incidence::List list;

  if ( !cal ) {
    kDebug() << "Can't parse clipboard";
    return list;
  }

  // All pasted incidences get new uids, must keep track of old uids,
  // so we can update child's parents
  QHash<QString,Incidence*> oldUidToNewInc;

  Incidence::List::ConstIterator it;
  const Incidence::List incs = cal->incidences();
  for ( it = incs.constBegin();
        it != incs.constEnd(); ++it ) {
    Incidence *inc = d->pasteIncidence( *it, newDate, newTime );
    if ( inc ) {
      list.append( inc );
      oldUidToNewInc[( *it )->uid()] = inc;
    }
  }

  // update relations
  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
    Incidence *inc = *it;
    if ( oldUidToNewInc.contains( inc->relatedToUid() ) ) {
      Incidence *parentInc = oldUidToNewInc[inc->relatedToUid()];
      inc->setRelatedToUid( parentInc->uid() );
      inc->setRelatedTo( parentInc );
    } else {
      // not related to anything in the clipboard
      inc->setRelatedToUid( QString() );
      inc->setRelatedTo( 0 );
    }
  }

  return list;
}
Example #28
0
	boost::shared_ptr<VanillaSwap> InstrumentFactory::make_vanillaSwap(Real notional,
																	const Date& ref_date,
																	const std::string& swap_index_cd,
																	Rate fixedRate,
																	VanillaSwap::Type fixedPayRecType,
																	Spread floatingLegSpread,
																	const Handle<YieldTermStructure>& evalYieldCurve,
																	const boost::shared_ptr<PricingEngine>& engine )
	{
		// 로드해

		boost::shared_ptr<SwapIndex> swapIndex = IndexFactory::swapIndex(swap_index_cd, evalYieldCurve.currentLink());

		Calendar calendar = SouthKorea();
		Period maturityTenor = swapIndex->tenor();
		Period couponTenor = swapIndex->fixedLegTenor();
		DayCounter dayCounter = swapIndex->dayCounter();
		BusinessDayConvention businessDayConvention = BusinessDayConvention::ModifiedFollowing;

		Schedule schedule = Schedule(ref_date,
			calendar.advance(ref_date, maturityTenor, businessDayConvention),
			couponTenor,
			calendar,
			businessDayConvention,
			businessDayConvention,
			DateGeneration::Rule::Forward,
			false);

		boost::shared_ptr<VanillaSwap> vanilla_swap
			= boost::shared_ptr<VanillaSwap>(new VanillaSwap(fixedPayRecType,
			notional,
			schedule,
			fixedRate, dayCounter,
			schedule,
			swapIndex->iborIndex()->clone(evalYieldCurve),
			floatingLegSpread,
			dayCounter));

		vanilla_swap->setPricingEngine(engine);

		return vanilla_swap;
	}
void PayoffManager::initialize(const TimeGrid& timeGrid, const Calendar& calendar){
			
		Date today = Settings::instance().evaluationDate();
		Date issueDate = Date(27,Sep,2012);
		/*std::cout << issueDate.serialNumber() << std::endl;
		std::cout << payoffDate_.serialNumber() << std::endl;
		std::cout << payoffDate_.serialNumber() - issueDate.serialNumber() << std::endl;*/

		payoffDatesPosition_ = calendar.businessDaysBetween(issueDate,payoffDate_,true,false);
		//std::cout << payoffDatesPosition_;
}
Example #30
0
bool PlanTJScheduler::kplatoToTJ()
{
    m_tjProject = new TJ::Project();
    m_tjProject->setScheduleGranularity( m_granularity / 1000 );
    m_tjProject->getScenario( 0 )->setMinSlackRate( 0.0 ); // Do not caclulate critical path

    m_tjProject->setNow( m_project->constraintStartTime().toTime_t() );
    m_tjProject->setStart( m_project->constraintStartTime().toTime_t() );
    m_tjProject->setEnd( m_project->constraintEndTime().toTime_t() );

    m_tjProject->setDailyWorkingHours( m_project->standardWorktime()->day() );

    // Set working days for the project, it is used for tasks with a length specification
    // FIXME: Plan has task specific calendars for this estimate type
    KPlato::Calendar *cal = m_project->defaultCalendar();
    if ( ! cal ) {
        m_project->calendars().value( 0 );
    }
    if ( cal ) {
        int days[ 7 ] = { Qt::Sunday, Qt::Monday, Qt::Tuesday, Qt::Wednesday, Qt::Thursday, Qt::Friday, Qt::Saturday };
        for ( int i = 0; i < 7; ++i ) {
            CalendarDay *d = 0;
            for ( Calendar *c = cal; c; c = c->parentCal() ) {
                QTime t; t.start();
                d = c->weekday( days[ i ] );
                Q_ASSERT( d );
                if ( d == 0 || d->state() != CalendarDay::Undefined ) {
                    break;
                }
            }
            if ( d && d->state() == CalendarDay::Working ) {
                QList<TJ::Interval*> lst;
                foreach ( const TimeInterval *ti, d->timeIntervals() ) {
                    TJ::Interval *tji = new TJ::Interval( toTJInterval( ti->startTime(), ti->endTime(),tjGranularity() ) );
                    lst << tji;
                }
                m_tjProject->setWorkingHours( i, lst );
                qDeleteAll( lst );
            }
        }
    }