Example usage for java.util Calendar setMinimalDaysInFirstWeek

List of usage examples for java.util Calendar setMinimalDaysInFirstWeek

Introduction

In this page you can find the example usage for java.util Calendar setMinimalDaysInFirstWeek.

Prototype

public void setMinimalDaysInFirstWeek(int value) 

Source Link

Document

Sets what the minimal days required in the first week of the year are; For example, if the first week is defined as one that contains the first day of the first month of a year, call this method with value 1.

Usage

From source file:org.pentaho.di.core.row.ValueDataUtil.java

public static Object weekOfYearISO8601(ValueMetaInterface metaA, Object dataA) throws KettleValueException {
    if (dataA == null) {
        return null;
    }/*from w w  w. j  a v a 2s .c o  m*/

    Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
    calendar.setMinimalDaysInFirstWeek(4);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(metaA.getDate(dataA));
    return new Long(calendar.get(Calendar.WEEK_OF_YEAR));

}

From source file:org.pentaho.di.core.row.ValueDataUtil.java

public static Object yearOfDateISO8601(ValueMetaInterface metaA, Object dataA) throws KettleValueException {
    if (dataA == null) {
        return null;
    }//from  ww  w.jav a2  s .  com

    Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
    calendar.setMinimalDaysInFirstWeek(4);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(metaA.getDate(dataA));

    int week = calendar.get(Calendar.WEEK_OF_YEAR);
    int month = calendar.get(Calendar.MONTH);
    int year = calendar.get(Calendar.YEAR);

    // fix up for the year taking into account ISO8601 weeks
    if (week >= 52 && month == 0) {
        year--;
    }
    if (week <= 2 && month == 11) {
        year++;
    }

    return new Long(year);
}