Logo Search packages:      
Sourcecode: icu version File versions  Download package

void Calendar::computeTime ( UErrorCode status  )  [protected, virtual, inherited]

Converts Calendar's time field values to GMT as milliseconds.

Parameters:
status Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status. ICU 2.0

Definition at line 2527 of file calendar.cpp.

References Calendar::computeJulianDay(), Calendar::computeMillisInDay(), Calendar::computeZoneOffset(), Calendar::fStamp, Calendar::internalGet(), Calendar::internalSetTime(), Calendar::isLenient(), Grego::julianDayToMillis(), Calendar::newestStamp(), U_FAILURE, UCAL_AM_PM, UCAL_DST_OFFSET, UCAL_MILLISECOND, UCAL_MILLISECONDS_IN_DAY, UCAL_ZONE_OFFSET, and Calendar::validateFields().

Referenced by Calendar::updateTime().

                                             {
    if (!isLenient()) {
        validateFields(status);
        if (U_FAILURE(status)) {
            return;
        }
    }

    // Compute the Julian day
    int32_t julianDay = computeJulianDay();

    double millis = Grego::julianDayToMillis(julianDay);

#if defined (U_DEBUG_CAL)
    //  int32_t julianInsanityCheck =  (int32_t)ClockMath::floorDivide(millis, kOneDay);
    //  julianInsanityCheck += kEpochStartAsJulianDay;
    //  if(1 || julianInsanityCheck != julianDay) {
    //    fprintf(stderr, "%s:%d- D'oh- computed jules %d, to mills (%s)%.lf, recomputed %d\n",
    //            __FILE__, __LINE__, julianDay, millis<0.0?"NEG":"", millis, julianInsanityCheck);
    //  }
#endif

    int32_t millisInDay;

    // We only use MILLISECONDS_IN_DAY if it has been set by the user.
    // This makes it possible for the caller to set the calendar to a
    // time and call clear(MONTH) to reset the MONTH to January.  This
    // is legacy behavior.  Without this, clear(MONTH) has no effect,
    // since the internally set JULIAN_DAY is used.
    if (fStamp[UCAL_MILLISECONDS_IN_DAY] >= ((int32_t)kMinimumUserStamp) &&
        newestStamp(UCAL_AM_PM, UCAL_MILLISECOND, kUnset) <= fStamp[UCAL_MILLISECONDS_IN_DAY]) {
            millisInDay = internalGet(UCAL_MILLISECONDS_IN_DAY);
        } else {
            millisInDay = computeMillisInDay();
        }

        // Compute the time zone offset and DST offset.  There are two potential
        // ambiguities here.  We'll assume a 2:00 am (wall time) switchover time
        // for discussion purposes here.
        // 1. The transition into DST.  Here, a designated time of 2:00 am - 2:59 am
        //    can be in standard or in DST depending.  However, 2:00 am is an invalid
        //    representation (the representation jumps from 1:59:59 am Std to 3:00:00 am DST).
        //    We assume standard time, that is, 2:30 am is interpreted as 3:30 am DST.
        // 2. The transition out of DST.  Here, a designated time of 1:00 am - 1:59 am
        //    can be in standard or DST.  Both are valid representations (the rep
        //    jumps from 1:59:59 DST to 1:00:00 Std).
        //    Again, we assume standard time, that is, 1:30 am is interpreted as 1:30 am Std.
        // We use the TimeZone object, unless the user has explicitly set the ZONE_OFFSET
        // or DST_OFFSET fields; then we use those fields.
        if (fStamp[UCAL_ZONE_OFFSET] >= ((int32_t)kMinimumUserStamp) ||
            fStamp[UCAL_DST_OFFSET] >= ((int32_t)kMinimumUserStamp)) {
                millisInDay -= internalGet(UCAL_ZONE_OFFSET) + internalGet(UCAL_DST_OFFSET);
            } else {
                millisInDay -= computeZoneOffset(millis, millisInDay,status);
            }

            internalSetTime(millis + millisInDay);
}


Generated by  Doxygen 1.6.0   Back to index