Java Code Examples for java.util.Calendar#getWeeksInWeekYear()

The following examples show how to use java.util.Calendar#getWeeksInWeekYear() . 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: TimestampFormatter.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    // if week starts in last year, return 00
    // range 00 - 53
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.SUNDAY);
    c.setMinimalDaysInFirstWeek(7);
    c.setTimeInMillis(timestamp.getMillis());
    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        week = 0;
    } else if (weekYear > year) {
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
Example 2
Source File: TimestampFormatter.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setMinimalDaysInFirstWeek(4);
    c.setTimeInMillis(timestamp.getMillis());
    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        week = 0;
    } else if (weekYear > year) {
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
Example 3
Source File: TimestampFormatter.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.SUNDAY);
    c.setMinimalDaysInFirstWeek(7);
    c.setTimeInMillis(timestamp.getMillis());

    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        // get weeks from last year
        c.add(Calendar.DAY_OF_MONTH, -7);
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
Example 4
Source File: TimestampFormatter.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setMinimalDaysInFirstWeek(4);
    c.setTimeInMillis(timestamp.getMillis());

    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        // get weeks from last year
        c.add(Calendar.DAY_OF_MONTH, -7);
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
Example 5
Source File: TimestampFormatter.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    // if week starts in last year, return 00
    // range 00 - 53
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.SUNDAY);
    c.setMinimalDaysInFirstWeek(7);
    c.setTimeInMillis(timestamp.getMillis());
    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        week = 0;
    } else if (weekYear > year) {
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
Example 6
Source File: TimestampFormatter.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setMinimalDaysInFirstWeek(4);
    c.setTimeInMillis(timestamp.getMillis());
    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        week = 0;
    } else if (weekYear > year) {
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
Example 7
Source File: TimestampFormatter.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.SUNDAY);
    c.setMinimalDaysInFirstWeek(7);
    c.setTimeInMillis(timestamp.getMillis());

    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        // get weeks from last year
        c.add(Calendar.DAY_OF_MONTH, -7);
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
Example 8
Source File: TimestampFormatter.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setMinimalDaysInFirstWeek(4);
    c.setTimeInMillis(timestamp.getMillis());

    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        // get weeks from last year
        c.add(Calendar.DAY_OF_MONTH, -7);
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}