Java Code Examples for org.joda.time.DateTimeConstants#MILLIS_PER_HOUR

The following examples show how to use org.joda.time.DateTimeConstants#MILLIS_PER_HOUR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimelineToMusicService.java    From computoser with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Gets the tempo, depending on the rate of tweeting
 *
 * @param tweets
 * @return tempo
 */
private Tempo getTempo(List<Tweet> tweets, TimelineMusic meta) {
    long totalSpacingInMillis = 0;
    Tweet previousTweet = null;
    for (Tweet tweet : tweets) {
       if (previousTweet != null) {
           totalSpacingInMillis += Math.abs(previousTweet.getCreatedAt().getTime() - tweet.getCreatedAt().getTime());
       }
       previousTweet = tweet;
    }

    double averageSpacing = totalSpacingInMillis / (tweets.size() - 1);
    meta.setAverageSpacing(averageSpacing);

    if (averageSpacing > 3 * DateTimeConstants.MILLIS_PER_DAY) { //once every three days
        return Tempo.VERY_SLOW;
    } else if (averageSpacing > 1.5 * DateTimeConstants.MILLIS_PER_DAY) { // more than once every 1.5 days
        return Tempo.SLOW;
    } else if (averageSpacing > 16 * DateTimeConstants.MILLIS_PER_HOUR) { // more than once every 16 hours
        return Tempo.MEDIUM;
    } else if (averageSpacing > 4 * DateTimeConstants.MILLIS_PER_HOUR) { // more than once every 4 hours
        return Tempo.FAST;
    } else {
        return Tempo.VERY_FAST;
    }
}
 
Example 2
Source File: TestDateTimeZone.java    From joda-time-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMillisKeepLocal() {
    long millisLondon = TEST_TIME_SUMMER;
    long millisParis = TEST_TIME_SUMMER - 1L * DateTimeConstants.MILLIS_PER_HOUR;
    
    assertEquals(millisLondon, LONDON.getMillisKeepLocal(LONDON, millisLondon));
    assertEquals(millisParis, LONDON.getMillisKeepLocal(LONDON, millisParis));
    assertEquals(millisLondon, PARIS.getMillisKeepLocal(PARIS, millisLondon));
    assertEquals(millisParis, PARIS.getMillisKeepLocal(PARIS, millisParis));
    
    assertEquals(millisParis, LONDON.getMillisKeepLocal(PARIS, millisLondon));
    assertEquals(millisLondon, PARIS.getMillisKeepLocal(LONDON, millisParis));
    
    DateTimeZone zone = DateTimeZone.getDefault();
    try {
        DateTimeZone.setDefault(LONDON);
        assertEquals(millisLondon, PARIS.getMillisKeepLocal(null, millisParis));
    } finally {
        DateTimeZone.setDefault(zone);
    }
}
 
Example 3
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public long getDateTimeMillis(
        int year, int monthOfYear, int dayOfMonth,
        int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
        throws IllegalArgumentException {
    Chronology base;
    if ((base = getBase()) != null) {
        return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
                                      hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    }

    FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
    FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);

    return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
        + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
        + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
        + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
        + millisOfSecond;
}
 
Example 4
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public long getDateTimeMillis(
        int year, int monthOfYear, int dayOfMonth,
        int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
        throws IllegalArgumentException {
    Chronology base;
    if ((base = getBase()) != null) {
        return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
                                      hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    }

    FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
    FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);

    return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
        + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
        + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
        + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
        + millisOfSecond;
}
 
Example 5
Source File: 1_BasicChronology.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public long getDateTimeMillis(
        int year, int monthOfYear, int dayOfMonth,
        int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
        throws IllegalArgumentException {
    Chronology base;
    if ((base = getBase()) != null) {
        return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
                                      hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    }

    FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
    FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);

    return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
        + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
        + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
        + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
        + millisOfSecond;
}
 
Example 6
Source File: Nopol2017_0088_t.java    From coming with MIT License 6 votes vote down vote up
public long getDateTimeMillis(
        int year, int monthOfYear, int dayOfMonth,
        int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
        throws IllegalArgumentException {
    Chronology base;
    if ((base = getBase()) != null) {
        return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
                                      hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    }

    FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
    FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);

    return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
        + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
        + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
        + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
        + millisOfSecond;
}
 
Example 7
Source File: Nopol2017_0088_s.java    From coming with MIT License 6 votes vote down vote up
public long getDateTimeMillis(
        int year, int monthOfYear, int dayOfMonth,
        int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
        throws IllegalArgumentException {
    Chronology base;
    if ((base = getBase()) != null) {
        return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
                                      hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    }

    FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
    FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);

    return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
        + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
        + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
        + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
        + millisOfSecond;
}
 
Example 8
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 4 votes vote down vote up
public void printTo(
        Writer out, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        out.write(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        out.write('+');
    } else {
        out.write('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.writePaddedInteger(out, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields == 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields == 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields == 3) {
        return;
    }

    if (iShowSeparators) {
        out.write('.');
    }
    FormatUtils.writePaddedInteger(out, displayOffset, 3);
}
 
Example 9
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 4 votes vote down vote up
public void printTo(
        StringBuffer buf, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        buf.append(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.appendPaddedInteger(buf, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields <= 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields <= 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields <= 3) {
        return;
    }

    if (iShowSeparators) {
        buf.append('.');
    }
    FormatUtils.appendPaddedInteger(buf, displayOffset, 3);
}
 
Example 10
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 4 votes vote down vote up
public void printTo(
        Writer out, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        out.write(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        out.write('+');
    } else {
        out.write('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.writePaddedInteger(out, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields == 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields == 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields == 3) {
        return;
    }

    if (iShowSeparators) {
        out.write('.');
    }
    FormatUtils.writePaddedInteger(out, displayOffset, 3);
}
 
Example 11
Source File: Time_26_ZonedChronology_t.java    From coming with MIT License 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
 
Example 12
Source File: Time_26_ZonedChronology_s.java    From coming with MIT License 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
 
Example 13
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 4 votes vote down vote up
public void printTo(
        StringBuffer buf, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        buf.append(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.appendPaddedInteger(buf, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields <= 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields <= 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields <= 3) {
        return;
    }

    if (iShowSeparators) {
        buf.append('.');
    }
    FormatUtils.appendPaddedInteger(buf, displayOffset, 3);
}
 
Example 14
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(
        StringBuffer buf, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        buf.append(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.appendPaddedInteger(buf, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields <= 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields <= 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields <= 3) {
        return;
    }

    if (iShowSeparators) {
        buf.append('.');
    }
    FormatUtils.appendPaddedInteger(buf, displayOffset, 3);
}
 
Example 15
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(
        Writer out, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        out.write(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        out.write('+');
    } else {
        out.write('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.writePaddedInteger(out, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields == 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields == 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields == 3) {
        return;
    }

    if (iShowSeparators) {
        out.write('.');
    }
    FormatUtils.writePaddedInteger(out, displayOffset, 3);
}
 
Example 16
Source File: ZonedChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
 
Example 17
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(
        StringBuffer buf, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        buf.append(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.appendPaddedInteger(buf, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields <= 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields <= 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        buf.append(':');
    }
    FormatUtils.appendPaddedInteger(buf, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields <= 3) {
        return;
    }

    if (iShowSeparators) {
        buf.append('.');
    }
    FormatUtils.appendPaddedInteger(buf, displayOffset, 3);
}
 
Example 18
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(
        Writer out, long instant, Chronology chrono,
        int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
    if (displayZone == null) {
        return;  // no zone
    }
    if (displayOffset == 0 && iZeroOffsetPrintText != null) {
        out.write(iZeroOffsetPrintText);
        return;
    }
    if (displayOffset >= 0) {
        out.write('+');
    } else {
        out.write('-');
        displayOffset = -displayOffset;
    }

    int hours = displayOffset / DateTimeConstants.MILLIS_PER_HOUR;
    FormatUtils.writePaddedInteger(out, hours, 2);
    if (iMaxFields == 1) {
        return;
    }
    displayOffset -= hours * (int)DateTimeConstants.MILLIS_PER_HOUR;
    if (displayOffset == 0 && iMinFields == 1) {
        return;
    }

    int minutes = displayOffset / DateTimeConstants.MILLIS_PER_MINUTE;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, minutes, 2);
    if (iMaxFields == 2) {
        return;
    }
    displayOffset -= minutes * DateTimeConstants.MILLIS_PER_MINUTE;
    if (displayOffset == 0 && iMinFields == 2) {
        return;
    }

    int seconds = displayOffset / DateTimeConstants.MILLIS_PER_SECOND;
    if (iShowSeparators) {
        out.write(':');
    }
    FormatUtils.writePaddedInteger(out, seconds, 2);
    if (iMaxFields == 3) {
        return;
    }
    displayOffset -= seconds * DateTimeConstants.MILLIS_PER_SECOND;
    if (displayOffset == 0 && iMinFields == 3) {
        return;
    }

    if (iShowSeparators) {
        out.write('.');
    }
    FormatUtils.writePaddedInteger(out, displayOffset, 3);
}
 
Example 19
Source File: ZonedChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
 
Example 20
Source File: Ideas_2010_02_24.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Interval maybeOK(int x) {
    return new Interval(x * DateTimeConstants.MILLIS_PER_HOUR, (x + 1) * DateTimeConstants.MILLIS_PER_HOUR);
}