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

The following examples show how to use org.joda.time.DateTimeConstants#MILLIS_PER_DAY . 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: GregorianChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
long calculateFirstDayOfYearMillis(int year) {
    // Initial value is just temporary.
    int leapYears = year / 100;
    if (year < 0) {
        // Add 3 before shifting right since /4 and >>2 behave differently
        // on negative numbers. When the expression is written as
        // (year / 4) - (year / 100) + (year / 400),
        // it works for both positive and negative values, except this optimization
        // eliminates two divisions.
        leapYears = ((year + 3) >> 2) - leapYears + ((leapYears + 3) >> 2) - 1;
    } else {
        leapYears = (year >> 2) - leapYears + (leapYears >> 2);
        if (isLeapYear(year)) {
            leapYears--;
        }
    }

    return (year * 365L + (leapYears - DAYS_0000_TO_1970)) * DateTimeConstants.MILLIS_PER_DAY;
}
 
Example 2
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param instant millis from 1970-01-01T00:00:00Z
 */
int getDayOfWeek(long instant) {
    // 1970-01-01 is day of week 4, Thursday.

    long daysSince19700101;
    if (instant >= 0) {
        daysSince19700101 = instant / DateTimeConstants.MILLIS_PER_DAY;
    } else {
        daysSince19700101 = (instant - (DateTimeConstants.MILLIS_PER_DAY - 1))
            / DateTimeConstants.MILLIS_PER_DAY;
        if (daysSince19700101 < -3) {
            return 7 + (int) ((daysSince19700101 + 4) % 7);
        }
    }

    return 1 + (int) ((daysSince19700101 + 3) % 7);
}
 
Example 3
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 4
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the millis for the first week of a year.
 *
 * @param year  the year to use
 * @return millis
 */
long getFirstWeekOfYearMillis(int year) {
    long jan1millis = getYearMillis(year);
    int jan1dayOfWeek = getDayOfWeek(jan1millis);
    
    if (jan1dayOfWeek > (8 - iMinDaysInFirstWeek)) {
        // First week is end of previous year because it doesn't have enough days.
        return jan1millis + (8 - jan1dayOfWeek)
            * (long)DateTimeConstants.MILLIS_PER_DAY;
    } else {
        // First week is start of this year because it has enough days.
        return jan1millis - (jan1dayOfWeek - 1)
            * (long)DateTimeConstants.MILLIS_PER_DAY;
    }
}
 
Example 5
Source File: ParquetGroupConverter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void addInt(int value) {
  if (value > ParquetReaderUtility.DATE_CORRUPTION_THRESHOLD) {
    holder.value = (value - ParquetReaderUtility.CORRECT_CORRUPT_DATE_SHIFT) * DateTimeConstants.MILLIS_PER_DAY;
  } else {
    holder.value = value * (long) DateTimeConstants.MILLIS_PER_DAY;
  }
  writer.write(holder);
  setWritten();
}
 
Example 6
Source File: ParquetReaderUtility.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
* @param binaryTimeStampValue
*          hive, impala timestamp values with nanoseconds precision
*          are stored in parquet Binary as INT96 (12 constant bytes)
*
* @return  Unix Timestamp - the number of milliseconds since January 1, 1970, 00:00:00 GMT
*          represented by @param binaryTimeStampValue .
*/
 public static long getDateTimeValueFromBinary(Binary binaryTimeStampValue) {
   // This method represents binaryTimeStampValue as ByteBuffer, where timestamp is stored as sum of
   // julian day number (32-bit) and nanos of day (64-bit)
   NanoTime nt = NanoTime.fromBinary(binaryTimeStampValue);
   int julianDay = nt.getJulianDay();
   long nanosOfDay = nt.getTimeOfDayNanos();
   return (julianDay - JULIAN_DAY_NUMBER_FOR_UNIX_EPOCH) * DateTimeConstants.MILLIS_PER_DAY
       + nanosOfDay / NANOS_PER_MILLISECOND;
 }
 
Example 7
Source File: 1_BasicChronology.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the millis for the first week of a year.
 *
 * @param year  the year to use
 * @return millis
 */
long getFirstWeekOfYearMillis(int year) {
    long jan1millis = getYearMillis(year);
    int jan1dayOfWeek = getDayOfWeek(jan1millis);
    
    if (jan1dayOfWeek > (8 - iMinDaysInFirstWeek)) {
        // First week is end of previous year because it doesn't have enough days.
        return jan1millis + (8 - jan1dayOfWeek)
            * (long)DateTimeConstants.MILLIS_PER_DAY;
    } else {
        // First week is start of this year because it has enough days.
        return jan1millis - (jan1dayOfWeek - 1)
            * (long)DateTimeConstants.MILLIS_PER_DAY;
    }
}
 
Example 8
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param instant millis from 1970-01-01T00:00:00Z
 */
int getMillisOfDay(long instant) {
    if (instant >= 0) {
        return (int) (instant % DateTimeConstants.MILLIS_PER_DAY);
    } else {
        return (DateTimeConstants.MILLIS_PER_DAY - 1)
            + (int) ((instant + 1) % DateTimeConstants.MILLIS_PER_DAY);
    }
}
 
Example 9
Source File: 1_BasicChronology.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param instant millis from 1970-01-01T00:00:00Z
 */
int getYear(long instant) {
    // Get an initial estimate of the year, and the millis value that
    // represents the start of that year. Then verify estimate and fix if
    // necessary.

    // Initial estimate uses values divided by two to avoid overflow.
    long unitMillis = getAverageMillisPerYearDividedByTwo();
    long i2 = (instant >> 1) + getApproxMillisAtEpochDividedByTwo();
    if (i2 < 0) {
        i2 = i2 - unitMillis + 1;
    }
    int year = (int) (i2 / unitMillis);

    long yearStart = getYearMillis(year);
    long diff = instant - yearStart;

    if (diff < 0) {
        year--;
    } else if (diff >= DateTimeConstants.MILLIS_PER_DAY * 365L) {
        // One year may need to be added to fix estimate.
        long oneYear;
        if (isLeapYear(year)) {
            oneYear = DateTimeConstants.MILLIS_PER_DAY * 366L;
        } else {
            oneYear = DateTimeConstants.MILLIS_PER_DAY * 365L;
        }

        yearStart += oneYear;

        if (yearStart <= instant) {
            // Didn't go too far, so actually add one year.
            year++;
        }
    }

    return year;
}
 
Example 10
Source File: BasicWeekOfWeekyearDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public long remainder(long instant) {
    return super.remainder(instant + 3 * DateTimeConstants.MILLIS_PER_DAY);
}
 
Example 11
Source File: Ideas_2010_06_23.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public long daysFromNow2(int days) {
    return days * DateTimeConstants.MILLIS_PER_DAY + System.currentTimeMillis();
}
 
Example 12
Source File: TestBuddhistChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    SKIP = 1 * DateTimeConstants.MILLIS_PER_DAY;
    junit.textui.TestRunner.run(suite());
}
 
Example 13
Source File: Nopol2017_0088_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * @param instant millis from 1970-01-01T00:00:00Z
 * @param year precalculated year of millis
 */
int getDayOfYear(long instant, int year) {
    long yearStart = getYearMillis(year);
    return (int) ((instant - yearStart) / DateTimeConstants.MILLIS_PER_DAY) + 1;
}
 
Example 14
Source File: BasicWeekOfWeekyearDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public long roundCeiling(long instant) {
    return super.roundCeiling(instant + 3 * DateTimeConstants.MILLIS_PER_DAY)
        - 3 * DateTimeConstants.MILLIS_PER_DAY;
}
 
Example 15
Source File: Ideas_2010_06_23.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public long daysBefore(Date d, int days) {
    return d.getTime() - days * DateTimeConstants.MILLIS_PER_DAY;
}
 
Example 16
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param millis from 1970-01-01T00:00:00Z
 * @param year precalculated year of millis
 * @param month precalculated month of millis
 */
int getDayOfMonth(long millis, int year, int month) {
    long dateMillis = getYearMillis(year);
    dateMillis += getTotalMillisByYearMonth(year, month);
    return (int) ((millis - dateMillis) / DateTimeConstants.MILLIS_PER_DAY) + 1;
}
 
Example 17
Source File: ParquetGroupConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void addInt(int value) {
  holder.value = value * (long) DateTimeConstants.MILLIS_PER_DAY;
  writer.writeDateMilli(holder.value);
  setWritten();
}
 
Example 18
Source File: BasicWeekOfWeekyearDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public long roundFloor(long instant) {
    return super.roundFloor(instant + 3 * DateTimeConstants.MILLIS_PER_DAY)
        - 3 * DateTimeConstants.MILLIS_PER_DAY;
}
 
Example 19
Source File: BasicWeekOfWeekyearDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public long roundFloor(long instant) {
    return super.roundFloor(instant + 3 * DateTimeConstants.MILLIS_PER_DAY)
        - 3 * DateTimeConstants.MILLIS_PER_DAY;
}
 
Example 20
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the milliseconds for a particular date.
 *
 * @param year The year to use.
 * @param month The month to use
 * @param dayOfMonth The day of the month to use
 * @return millis from 1970-01-01T00:00:00Z
 */
long getYearMonthDayMillis(int year, int month, int dayOfMonth) {
    long millis = getYearMillis(year);
    millis += getTotalMillisByYearMonth(year, month);
    return millis + (dayOfMonth - 1) * (long)DateTimeConstants.MILLIS_PER_DAY;
}