Example usage for java.util Calendar WEEK_OF_YEAR

List of usage examples for java.util Calendar WEEK_OF_YEAR

Introduction

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

Prototype

int WEEK_OF_YEAR

To view the source code for java.util Calendar WEEK_OF_YEAR.

Click Source Link

Document

Field number for get and set indicating the week number within the current year.

Usage

From source file:de.ribeiro.android.gso.dataclasses.Pager.java

/**
 * Liefert den pageIndex des bergegebenen Datums
 *
 * @param currentDate//from   w  w  w . j  a  v  a 2s . c o m
 * @return
 * @author ribeiro
 */
public int getPage(Calendar currentDate, int defaultReturn) {
    int currentDayOfWeek = currentDate.get(Calendar.DAY_OF_WEEK);
    // den currentDay auf den folge Montag setzten
    if (currentDayOfWeek < 2) {
        // 1000*60*60*24 = 1 Tag!
        currentDate.setTimeInMillis(
                currentDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * (2 - currentDayOfWeek)));
    }
    if (currentDayOfWeek > 6) {
        // 1000*60*60*24 = 1 Tag!
        currentDate.setTimeInMillis(currentDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2));
    }

    int dayOfYearcurrent = 0;
    int weekOfYearcurrent = 0;
    int dayOfYearpage = 0;
    int weekOfYearpage = 0;
    int yearCurrent = 0;
    int yearPage = 0;

    int nextPage = defaultReturn;
    // alle Seiten des Pages durchlaufen und das Datum abfragen und mit dem
    // gewnschten Datum vergleichen
    for (int i = 0; i < pageIndex.size(); i++) {
        dayOfYearcurrent = currentDate.get(Calendar.DAY_OF_YEAR);
        weekOfYearcurrent = currentDate.get(Calendar.WEEK_OF_YEAR);
        yearCurrent = currentDate.get(Calendar.YEAR);
        dayOfYearpage = pageIndex.get(i).get(Calendar.DAY_OF_YEAR);
        weekOfYearpage = pageIndex.get(i).get(Calendar.WEEK_OF_YEAR);
        yearPage = pageIndex.get(i).get(Calendar.YEAR);

        // prfen auf was getestet werden soll(wochenansicht, oder
        // tagesansicht)
        if (context.getResources()
                .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT) {
            // Tagesansicht
            if (yearPage < yearCurrent) {
                nextPage = i;
                if (dayOfYearpage < dayOfYearcurrent)
                    nextPage = i;
            }
            if ((dayOfYearcurrent == dayOfYearpage) && (yearCurrent == yearPage))
                return i;
            else if ((dayOfYearcurrent < dayOfYearpage) && (yearCurrent == yearPage))
                return i;
        } else if (context.getResources()
                .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) {
            // Wochenansicht
            if (yearPage < yearCurrent) {
                nextPage = i;
                if (dayOfYearpage < dayOfYearcurrent)
                    nextPage = i;
            }
            if ((weekOfYearcurrent == weekOfYearpage) && (yearCurrent == yearPage))
                return i;
            else if ((weekOfYearcurrent < weekOfYearpage) && (yearCurrent == yearPage))
                return i;
        }
    }

    // dies kommt nur vor, wenn die Seite nicht gefunden wurde. dann wird
    // die nchst kleinere Seite zurckgeliefert
    return nextPage;

}

From source file:com.rogchen.common.xml.UtilDateTime.java

public static int getWeek(Timestamp stamp, TimeZone timeZone, Locale locale) {
    Calendar cal = UtilDateTime.toCalendar(stamp, timeZone, locale);
    return cal.get(Calendar.WEEK_OF_YEAR);
}

From source file:kobytest.KobyTest.java

public static void pedir_historico(final int id_valor, String symbol, int weeks_ago)
        throws SQLException, ParseException {

    System.out.println("Requesting historic data for :" + id_valor);

    //0 weeks ago is this weekd
    Calendar cal = Calendar.getInstance();
    int current_week = cal.get(Calendar.WEEK_OF_YEAR);
    int current_day = cal.get(Calendar.DAY_OF_MONTH);
    int current_month = cal.get(Calendar.MONTH) + 1;
    int current_year = cal.get(Calendar.YEAR);

    System.out.println("Current day is " + current_day);
    System.out.println("Current week is " + current_week);

    String year = "" + current_year;
    if (current_month == 1)
        current_month = 12;//from   ww w  . j  a v  a 2  s  .c  o m
    String month = "" + current_month;
    String day = "01";

    for (int i = 0; i < weeks_ago; i++) {
        System.out.println("i = " + i + ". id_valor=" + id_valor + ". valorestabla[id_valor]"
                + valores_tabla.get(id_valor));
        historico_valores.get(valores_tabla.get(id_valor)).put(i, null);
    }

    final Contract contract = new Contract();
    //contract.m_comboLegs
    //contract.m_comboLegsDescrip
    //contract.m_conId = 11;
    contract.m_currency = "USD";
    contract.m_exchange = "SMART";
    //contract.m_expiry;
    contract.m_includeExpired = false;
    //contract.m_localSymbol = "KO";
    //contract.m_multiplier;
    //        contract.m_primaryExch = "NASDAQ";
    //        contract.m_right = "CALL";
    //contract.m_secId;
    //contract.m_secIdType;
    contract.m_secType = "STK"; // stock
    String simbolo = valores_tabla.get(id_valor);
    contract.m_symbol = simbolo; // symbol
    //contract.m_tradingClass;
    //int id, Contract contract, String endDateTime, String durationStr, String barSizeSetting, String whatToShow, int useRTH, int formatDate, List<TagValue> chartOptions

    //TODO
    // -semana: buscar el fin de la semana. Calcular a partir de la semana // format yyyymmdd hh:mm:ss tmz, where the time zone is allowed (optionally) after a space at the end.
    Calendar cal_last_sunday = Calendar.getInstance();
    //        cal_last_sunday.set(Calendar.WEEK_OF_YEAR, current_week);
    cal_last_sunday.set(Calendar.WEEK_OF_YEAR, current_week - 1);
    cal_last_sunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    //        cal_last_sunday.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);

    int last_sunday_day = cal_last_sunday.get(Calendar.DAY_OF_MONTH);
    int last_sunday_month = cal_last_sunday.get(Calendar.MONTH) + 1;
    //        int last_sunday_month = cal_last_sunday.get(Calendar.MONTH);
    int last_sunday_year = cal_last_sunday.get(Calendar.YEAR);

    String last_sunday_year_str = String.valueOf(last_sunday_year);
    String last_sunday_month_str = String.valueOf(last_sunday_month);
    if (last_sunday_month < 10) {
        last_sunday_month_str = "0" + last_sunday_month_str;
    }
    String last_sunday_day_str = String.valueOf(last_sunday_day);
    if (last_sunday_day < 10) {
        last_sunday_day_str = "0" + last_sunday_day_str;
    }

    String semana = last_sunday_year_str + last_sunday_month_str + last_sunday_day_str + " 16:00:00 EST"; // de la primera semana

    String current_year_str = String.valueOf(current_year);
    String current_month_str = String.valueOf(current_month);
    if (current_month < 10) {
        current_month_str = "0" + current_month_str;
    }
    String current_day_str = String.valueOf(current_day);
    if (current_day < 10) {
        current_day_str = "0" + current_day_str;
    }

    Calendar c = Calendar.getInstance();
    Calendar c1 = Calendar.getInstance();
    c.add(Calendar.DATE, 0);
    SimpleDateFormat d = new SimpleDateFormat("yyyyMMdd");
    Date date = c.getTime();
    Date dateW = c1.getTime();
    strSemana = d.format(date);
    strWeek = d.format(dateW);

    Calendar calendar = Calendar.getInstance(Locale.forLanguageTag("en-US"));
    calendar.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    String hour = calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE) + ":00";
    //semana = current_year_str + current_month_str + current_day_str + " "+hour+" America/New_York";//EST
    semana = strSemana + " 09:00:00 EST";
    final String semanaTimer = semana;
    System.out.println("Requestion values for " + strSemana);
    final String duracion = 1 + " D"; // pedimos todas las semanas
    final String duracionTimer = 1 + " D"; // pedimos todas las semanas
    final String barSizeSetting = "1 day";
    final String whatToShow = "TRADES";
    final int useRTH = 1; //only data that falls within regular trading hours.
    final int formatDate = 1;//1 - dates applying to bars returned in the format:yyyymmdd{space}{space}hh:mm:dd       2 - dates are returned as a long integer specifying the number of seconds since 1/1/1970 GMT.
    //        List chartOptions = null;
    final Vector chartOptions = new Vector();
    symbol_current = symbol;

    String fecha = current_year + "-" + current_month + "-" + current_day;
    //        ResultSet exsiste = DDBB.lowHighFecha(fecha);
    //        ResultSet exsisteTicker = DDBB.lowHighFechaName(fecha, symbol);d?
    count++;
    HistoricalDataReq historial = new HistoricalDataReq();
    peticionesHistorical[count].id = id_valor;
    peticionesHistorical[count].contract = contract;
    peticionesHistorical[count].endDateTime = semana;
    peticionesHistorical[count].durationStr = duracion;
    peticionesHistorical[count].barSizeSetting = barSizeSetting;
    peticionesHistorical[count].whatToShow = whatToShow;
    peticionesHistorical[count].useRTH = useRTH;
    peticionesHistorical[count].formatDate = formatDate;
    peticionesHistorical[count].chartOptions = chartOptions;
    peticionesHistorical[count].ticker = symbol;

    // peticionesHistorical[count] = historial;

    System.out.println("--------------------------------------------------------------------------------------"
            + historial.id + " " + symbol);

    //       connection.reqHistoricalData(id_valor, contract, semanaTimer, duracion, barSizeSetting, whatToShow, useRTH, formatDate, chartOptions);

    //        try {
    //
    //            Thread t = new Thread(new Runnable() {
    //
    //                @Override
    //                public void run() { 
    //                    int num = 1000;
    //                        ResultSet dat = DDBB.TickersAll();
    //                    try {
    //                        Thread.sleep((int)(Math.random()*((16000*num)-1000+1)+1000));
    //                    } catch (InterruptedException ex) {
    //                        Logger.getLogger(KobyTest.class.getName()).log(Level.SEVERE, null, ex);
    //                    }
    //                        
    //                    try {
    //                        if(dat.next())num=dat.getInt("id");
    //                    } catch (SQLException ex) {
    //                        Logger.getLogger(KobyTest.class.getName()).log(Level.SEVERE, null, ex);
    //                    }
    //                       Timer timer = new Timer ((int)(Math.random()*((16000*num)-1000+1)+1000), new ActionListener () { 
    //                        public void actionPerformed(ActionEvent e) 
    //                        { 
    //                            connection.reqHistoricalData(id_valor, contract, semanaTimer, duracionTimer, barSizeSetting, whatToShow, useRTH, formatDate, chartOptions);
    //                         } 
    //                        }); 
    //                        timer.start();
    //                   
    //                }
    //            });
    //            t.start();
    //
    //        } catch (Exception ex) {
    //            Logger.getLogger(Semaforo.class.getName()).log(Level.SEVERE, null, ex);
    //        }
    //        id_ant = id_valor;

    //        connection.reqHistoricalData(id_valor, contract, semana, "300 S", "1 secs", whatToShow, useRTH, formatDate, chartOptions);
    //        if(!exsiste.next()){ System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
    //            DDBB.deleteLowHigh();
    //            connection.reqHistoricalData(id_valor, contract, semana, duracion, barSizeSetting, whatToShow, useRTH, formatDate, chartOptions);
    //        }else if(newTicker){
    //            System.out.println("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
    //            connection.reqHistoricalData(id_valor, contract, semana, duracion, barSizeSetting, whatToShow, useRTH, formatDate, chartOptions);
    //            newTicker = false;
    //        }else if(!exsisteTicker.next()){
    //            System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    //            connection.reqHistoricalData(id_valor, contract, semana, duracion, barSizeSetting, whatToShow, useRTH, formatDate, chartOptions);
    //            newTicker = false;
    //        }

}

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

public static Object weekOfYear(ValueMetaInterface metaA, Object dataA) throws KettleValueException {
    if (dataA == null) {
        return null;
    }//from ww  w . j  av  a2  s. c  o m

    Calendar calendar = Calendar.getInstance();
    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 weekOfYearISO8601(ValueMetaInterface metaA, Object dataA) throws KettleValueException {
    if (dataA == null) {
        return null;
    }/*from  w  w  w  .  j  a  v  a2s .  co  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;
    }//w ww .  j a va  2 s.  c om

    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);
}

From source file:com.frameworkset.platform.sanylog.action.CounterController.java

@SuppressWarnings("rawtypes")
public @ResponseBody String operCountCompare(String type, String appId, String time) throws Exception {
    if ("".equals(appId) || null == appId) {
        return null;
    }/*ww w.j av  a 2s . c  o m*/
    String tableName = "";
    float divisor = 1;
    if ("day".equals(type)) {
        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            time = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN);
        }

        tableName = "TD_LOG_OPERSTATIC_BYDAY";
        divisor = 30;

    } else if ("week".equals(type)) {

        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            String todayTime = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN);
            String week = String.valueOf(today.get(Calendar.WEEK_OF_YEAR));
            time = todayTime.substring(0, 4) + "-" + week;
        }

        tableName = "TD_LOG_OPERSTATIC_BYWEEK";
        divisor = 4;

    } else if ("month".equals(type)) {
        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            time = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN).substring(0, 7);
        }

        tableName = "TD_LOG_OPERSTATIC_BYMONTH";
        divisor = 1;
    } else if ("year".equals(type)) {
        if ("".equals(time) || null == time) {
            Calendar today = Calendar.getInstance();
            time = DateUtils.format(today.getTime(), DateUtils.ISO8601_DATE_PATTERN).substring(0, 4);
        }
        tableName = "TD_LOG_OPERSTATIC_BYYEAR";
        divisor = (float) 0.083;
    }
    List<OperChart> datas = counterManager.getOperChartCount(appId, time, tableName, divisor);
    String dataXML = "<chart xAxisName = '??' yAxisName='' showValues='0'>";
    dataXML += "<dataset label='' value='' />";
    String categories = "<categories>";
    String datasetSim = "<dataset seriesName=''>";
    String datasetCom = "<dataset seriesName=''>";
    if (datas.size() > 0) {
        for (OperChart bean : datas) {
            categories += "<category label=' " + bean.getModuleName() + " ' />";
            datasetSim += "<set value='" + bean.getVcount() + "' />";
            datasetCom += "<set value='" + bean.getEstimateOper() + "' />";
        }
    }
    categories += "</categories>";
    datasetSim += "</dataset>";
    datasetCom += "</dataset>";
    dataXML += categories + datasetSim + datasetCom;
    dataXML += "</chart>";
    return dataXML;

}

From source file:com.rogchen.common.xml.UtilDateTime.java

public static Date addWeek(Date date, int addWeek) {
    return addInteger(date, Calendar.WEEK_OF_YEAR, addWeek);
}

From source file:com.rogchen.common.xml.UtilDateTime.java

public static Date plusWeek(Date date, int plusWeek) {
    return plusInteger(date, Calendar.WEEK_OF_YEAR, plusWeek);
}

From source file:edu.jhuapl.openessence.controller.ReportController.java

/**
 * Compute end date based on time resolution. Defaults to the original date unless the resolution is weekly, monthly
 * or yearly in which case it is padded accordingly.
 *
 * @param maxDate optionally used to keep the computed date below a maxDate (end date for the query for example)
 * @return Date//from   w  w  w . jav  a2  s  .  co  m
 */
private Date computeResolutionBasedEndDate(Date startDate, String timeResolution, Date maxDate) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(startDate);
    if (WEEKLY.equalsIgnoreCase(timeResolution)) {
        cal.add(Calendar.WEEK_OF_YEAR, 1);
        cal.add(Calendar.DATE, -1);
    } else if (MONTHLY.equalsIgnoreCase(timeResolution)) {
        cal.add(Calendar.MONTH, 1);
        cal.add(Calendar.DATE, -1);
    } else if (YEARLY.equalsIgnoreCase(timeResolution)) {
        cal.add(Calendar.YEAR, 1);
        cal.add(Calendar.DATE, -1);
    } else {
        //do nothing for daily currently
    }
    //we want the end date/label to not exceed the query end date
    if (maxDate != null && cal.getTime().after(maxDate)) {
        cal.setTime(maxDate);
    }
    return cal.getTime();
}