List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:org.ramadda.util.Utils.java
/** * _more_/*from www. j a va 2s . co m*/ * * @param f _more_ * * @return _more_ */ public static String normalizeTemplateUrl(String f) { StringBuilder s = new StringBuilder(); Date now = new Date(); GregorianCalendar g = new GregorianCalendar(); Date currentDate = now; TimeZone tz = TimeZone.getTimeZone("UTC"); g.setTime(currentDate); //Old macros if (f.indexOf("${now") >= 0) { f = f.replace("${now.year}", g.get(g.YEAR) + ""); f = f.replace("${now.month}", StringUtil.padZero(g.get(g.MONTH), 2)); f = f.replace("${now.day}", StringUtil.padZero(g.get(g.DAY_OF_MONTH), 2)); f = f.replace("${now.hour}", StringUtil.padZero(g.get(g.HOUR_OF_DAY), 2)); f = f.replace("${now.minute}", StringUtil.padZero(g.get(g.MINUTE), 2)); } List<String> toks = StringUtil.splitMacros(f); for (int i = 0; i < toks.size(); i++) { String t = toks.get(i); //System.err.println("T:" + t); if (i / 2.0 == (int) i / 2) { s.append(t); //System.err.println("appending"); continue; } String d = null; if (t.startsWith("z:")) { tz = TimeZone.getTimeZone(t.substring(2)); continue; } if (t.startsWith("date:")) { t = t.substring(5).trim(); Date newDate = null; if (t.equals("now")) { newDate = now; } else { newDate = DateUtil.getRelativeDate(now, t); } if (newDate != null) { currentDate = newDate; g.setTime(currentDate); } continue; } if (t.startsWith("format:")) { t = t.substring("format:".length()).trim(); SimpleDateFormat sdf = makeDateFormat(t); sdf.setTimeZone(tz); s.append(sdf.format(currentDate)); continue; } if (t.startsWith("year")) { d = g.get(g.YEAR) + ""; } else if (t.startsWith("month")) { d = StringUtil.padZero(g.get(g.MONTH), 2); } else if (t.startsWith("day")) { d = StringUtil.padZero(g.get(g.DAY_OF_MONTH), 2); } else if (t.startsWith("hour")) { d = StringUtil.padZero(g.get(g.HOUR_OF_DAY), 2); } else if (t.startsWith("minute")) { d = StringUtil.padZero(g.get(g.MINUTE), 2); } else { //Put it back d = "${" + t + "}"; // System.err.println("Unknown macro:" + t); // continue; } s.append(d); } return s.toString(); }
From source file:PVGraph.java
public java.util.List<PeriodData> getMonthData(int year, int month) { Statement stmt = null;/*from w w w. ja v a2 s. c om*/ String query = "select * from DayData where year(DateTime) = " + year + " and month(DateTime) = " + month + " and CurrentPower != 0 order by DateTime"; Map<String, PeriodData> result = new HashMap<String, PeriodData>(); GregorianCalendar gc = new GregorianCalendar(); try { getDatabaseConnection(); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String serial = rs.getString("serial"); PeriodData pd = result.get(serial); if (pd == null) { pd = new PeriodData(); pd.serial = serial; pd.inverter = rs.getString("inverter"); pd.startTotalPower = rs.getDouble("ETotalToday"); gc.setTime(rs.getTimestamp("DateTime")); gc.set(Calendar.DAY_OF_MONTH, 1); gc.add(Calendar.MONTH, 1); gc.add(Calendar.DAY_OF_MONTH, -1); pd.numPowers = gc.get(Calendar.DAY_OF_MONTH); result.put(serial, pd); } double power = rs.getDouble("ETotalToday"); gc.setTime(rs.getTimestamp("DateTime")); pd.powers[gc.get(Calendar.DAY_OF_MONTH) - 1] = power; pd.endTotalPower = power; } } catch (SQLException e) { System.err.println("Query failed: " + e.getMessage()); } finally { try { stmt.close(); } catch (SQLException e) { // relax } } return new java.util.ArrayList<PeriodData>(result.values()); }
From source file:cx.fbn.nevernote.sql.REnSearch.java
private GregorianCalendar stringToGregorianCalendar(String date) { String datePart = date;/*from w w w. ja v a 2s. c o m*/ GregorianCalendar calendar = new GregorianCalendar(); boolean GMT = false; String timePart = ""; if (date.contains("T")) { datePart = date.substring(0, date.indexOf("T")); timePart = date.substring(date.indexOf("T") + 1); } else { timePart = "000001"; } if (datePart.length() != 8) return null; calendar.set(Calendar.YEAR, new Integer(datePart.substring(0, 4))); calendar.set(Calendar.MONTH, new Integer(datePart.substring(4, 6)) - 1); calendar.set(Calendar.DAY_OF_MONTH, new Integer(datePart.substring(6))); if (timePart.endsWith("Z")) { GMT = true; timePart = timePart.substring(0, timePart.length() - 1); } timePart = timePart.concat("000000"); timePart = timePart.substring(0, 6); calendar.set(Calendar.HOUR, new Integer(timePart.substring(0, 2))); calendar.set(Calendar.MINUTE, new Integer(timePart.substring(2, 4))); calendar.set(Calendar.SECOND, new Integer(timePart.substring(4))); if (GMT) calendar.set(Calendar.ZONE_OFFSET, -1 * (calendar.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60))); return calendar; }
From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java
@Override protected void readParameter() { GregorianCalendar gToday = new GregorianCalendar( TimeZone.getTimeZone(mContext.getResources().getString(R.string.my_time_zone_en))); SharedPreferences sharedPref = mContext.getSharedPreferences(MainActivity.package_name + ".profile", Context.MODE_PRIVATE); String param = sharedPref.getString(MainActivity.ONE_BOOT_PARAMS, "--"); Set<String> aSet = sharedPref.getStringSet(MainActivity.SET_ONE_BOOT, null); if (aSet == null) { last4 = -1;/*from w ww.j a v a 2 s .c o m*/ return; } String[] allData = new String[aSet.size()]; allData = aSet.toArray(allData); String todayName = ScheduleActivity.weekDays[(gToday.get(Calendar.DAY_OF_WEEK) + 6) % 7];//ScheduleActivity.weekDays[gToday.get(Calendar.DAY_OF_WEEK)-1]; param = null; for (int i = 0; i < aSet.size(); i++) { if (allData[i].indexOf(todayName) < 0) continue; param = allData[i].replace('>', '-'); //saved data format change to weekdayName>HH:MM-last4 //data has form hh:mm-active period break; } if (param == null) { last4 = -1; return; } String[] terms = param.split("-"); int iH = Integer.parseInt(terms[1].substring(0, 2)); int iM = Integer.parseInt(terms[1].substring(3)); int iHr = gToday.get(Calendar.HOUR_OF_DAY); int iMin = gToday.get(Calendar.MINUTE); init_wait = ((iH - iHr) * 60 + (iM - iMin)) * 60 * 1000; //in milli secs on_time = 60 * 1000 * Integer.parseInt(terms[2]); //if (init_wait>0) last4 = on_time; if (init_wait < -1 * 60 * 1000) on_time = -1; //in milli secs //last4=init_wait+end_time; }
From source file:Logica.Usuario.java
@Override public String getFecha() throws RemoteException { GregorianCalendar hoy = new GregorianCalendar(); String cadenaFecha = hoy.get(Calendar.DAY_OF_MONTH) + "/" + (hoy.get(Calendar.MONTH) + 1) + "/" + hoy.get(Calendar.YEAR); return cadenaFecha; }
From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java
@Override protected void readParameter() { GregorianCalendar gToday = new GregorianCalendar( TimeZone.getTimeZone(mContext.getResources().getString(R.string.my_time_zone_en))); SharedPreferences sharedPref = mContext.getSharedPreferences(MainActivity.package_name + ".profile", Context.MODE_PRIVATE); String param = sharedPref.getString(MainActivity.N_BOOT_PARAMS, "--"); Set<String> aSet = sharedPref.getStringSet(MainActivity.SET_MULTIPLE_BOOT, null); if (aSet == null) { last4 = -1;/*from ww w. java 2 s . c om*/ return; } String[] allData = new String[aSet.size()]; allData = aSet.toArray(allData); String todayName = ScheduleActivity.weekDays[(gToday.get(Calendar.DAY_OF_WEEK) + 6) % 7]; String yesterday = ScheduleActivity.weekDays[(gToday.get(Calendar.DAY_OF_WEEK) + 5) % 7]; int hrNow = gToday.get(Calendar.HOUR_OF_DAY); param = null; for (int i = 0; i < aSet.size(); i++) { if (allData[i].indexOf(todayName) < 0) continue; param = allData[i].replace('>', '-'); //saved data format change to weekdayName>HH:MM-last4 //data has form hh:mm-active period break; } if (hrNow > 7 && param == null) { last4 = -1; return; } int hrBase = 0; String param0 = null; if (hrNow < 7) { if (param != null) { int idd = param.indexOf("-"); int h0 = Integer.parseInt(param.substring(idd + 1, idd + 3)); if (h0 > 7) param = null; } if (param == null) { for (int i = 0; i < aSet.size(); i++) { if (allData[i].indexOf(yesterday) < 0) continue; param = allData[i].replace('>', '-'); break; } if (param == null) { last4 = -1; return; } int idd = param.indexOf("-"); int h0 = Integer.parseInt(param.substring(idd + 1, idd + 3)); if (h0 < 21) { last4 = -1; return; } hrBase = 24; } } Log.i("SCHEDULE_JOB", "found parameters " + param + " as new schedule"); String[] terms = param.split("-"); int icx = terms[1].indexOf(":"); if (icx < 0) { last4 = -1; return; } int hrStart = Integer.parseInt(terms[1].substring(0, icx)); //starting hour int minStart = Integer.parseInt(terms[1].substring(icx + 1)); hrNow += hrBase; //int hrEnd=7+hrBase; int minNow = gToday.get(Calendar.MINUTE); on_time = 1000 * 60 * Integer.parseInt(terms[2]); //in milli secs off_time = 1000 * 3600 * Integer.parseInt(terms[3]); //in milli secs init_wait = ((hrStart - hrNow) * 60 + (minStart - minNow)) * 60 * 1000; //in milli secs while (init_wait < 0) { init_wait += (on_time + off_time); } //change the end time to 07:00AM //int endHr=7; // if (iH > 7) endHr=7+24; //end_time=((endHr-iH)*60+(0-iM))*60*1000; //end_time=1000*60*Integer.parseInt(terms[3]); //in milli secs //last4=init_wait+end_time; last4 = 1000; }
From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java
public String readBootParameter(int mode_1_n) { String retS = null;// w ww .j ava 2 s .co m GregorianCalendar gToday = new GregorianCalendar( TimeZone.getTimeZone(getResources().getString(R.string.my_time_zone_en))); SharedPreferences sharedPref = getSharedPreferences(MainActivity.package_name + ".profile", Context.MODE_PRIVATE); String param = sharedPref.getString(MainActivity.ONE_BOOT_PARAMS, "--"); String paramKey = MainActivity.SET_MULTIPLE_BOOT; if (mode_1_n == 1) paramKey = MainActivity.SET_ONE_BOOT; Set<String> aSet = sharedPref.getStringSet(paramKey, null); if (aSet == null) { return null; } String[] allData = new String[aSet.size()]; allData = aSet.toArray(allData); String todayName = ScheduleActivity.weekDays[(gToday.get(Calendar.DAY_OF_WEEK) + 6) % 7];//ScheduleActivity.weekDays[gToday.get(Calendar.DAY_OF_WEEK)-1]; String scheduleDay = todayName; param = null; for (int i = 0; i < aSet.size(); i++) { if (allData[i].indexOf(scheduleDay) < 0) continue; param = allData[i].replace('>', '-'); //saved data format change to weekdayName>HH:MM-last4 //data has form hh:mm-active period break; } int hrNow = gToday.get(Calendar.HOUR_OF_DAY); if (param == null) { if (mode_1_n == 1 || hrNow > 7) return null; } if (mode_1_n != 1 && hrNow < 7) { if (param != null) { int idd = param.indexOf("-"); int h0 = Integer.parseInt(param.substring(idd + 1, idd + 3)); if (h0 > 7) param = null; } scheduleDay = ScheduleActivity.weekDays[(gToday.get(Calendar.DAY_OF_WEEK) + 5) % 7]; //check if scheduled yesterday if (param == null) { for (int i = 0; i < aSet.size(); i++) { if (allData[i].indexOf(scheduleDay) < 0) continue; param = allData[i].replace('>', '-'); break; } if (param == null) { return null; } int idd = param.indexOf("-"); int h0 = Integer.parseInt(param.substring(idd + 1, idd + 3)); if (h0 < 21) { return null; } hrNow += 24; //hrBase = 24; } } String[] terms = param.split("-"); int icx = terms[1].indexOf(":"); if (icx < 0) { Log.w("SCHEDULE_JOB", "!!! Bad formated start time " + param + " as new schedule"); return null; } int hrStart = Integer.parseInt(terms[1].substring(0, icx)); //starting hour int minStart = Integer.parseInt(terms[1].substring(icx + 1)); int minNow = gToday.get(Calendar.MINUTE); long init_wait = ((hrStart - hrNow) * 60 + (minStart - minNow)) * 60 * 1000; //in milli secs long on_time = 60 * 1000 * Integer.parseInt(terms[2]); //if (init_wait>0) if (mode_1_n == 1) { if (init_wait < -2 * 60 * 1000) return null; if (init_wait < 0) init_wait = 0; if (on_time < 1) return null; //if (init_wait >3605000) return null; retS = "" + init_wait + "-" + on_time; return retS; } long off_time = 1000 * 3600 * Integer.parseInt(terms[3]); //in milli secs while (init_wait < 0) { init_wait += off_time;//(on_time+off_time); } retS = "" + init_wait + "-" + on_time + "-" + off_time; return retS; }
From source file:org.apache.flink.client.web.JobsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter(ACTION_PARAM_NAME); if (action.equals(ACTION_LIST_VALUE)) { GregorianCalendar cal = new GregorianCalendar(); File[] files = destinationDir.listFiles(); Arrays.<File>sort(files, FILE_SORTER); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(CONTENT_TYPE_PLAIN); PrintWriter writer = resp.getWriter(); for (int i = 0; i < files.length; i++) { if (!files[i].getName().endsWith(".jar")) { continue; }//from www . ja va2 s . co m JarFile jar = new JarFile(files[i]); Manifest manifest = jar.getManifest(); String assemblerClass = null; String descriptions = ""; if (manifest != null) { assemblerClass = manifest.getMainAttributes() .getValue(PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS); if (assemblerClass == null) { assemblerClass = manifest.getMainAttributes() .getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS); } } if (assemblerClass == null) { assemblerClass = ""; } else { String[] classes = assemblerClass.split(","); for (String c : classes) { try { String d = new PackagedProgram(files[i], c, new String[0]).getDescription(); if (d == null) { d = "No description provided."; } descriptions += "#_#" + d; } catch (ProgramInvocationException e) { descriptions += "#_#No description provided."; continue; } } assemblerClass = '\t' + assemblerClass; } cal.setTimeInMillis(files[i].lastModified()); writer.println(files[i].getName() + '\t' + (cal.get(GregorianCalendar.MONTH) + 1) + '/' + cal.get(GregorianCalendar.DAY_OF_MONTH) + '/' + cal.get(GregorianCalendar.YEAR) + ' ' + cal.get(GregorianCalendar.HOUR_OF_DAY) + ':' + cal.get(GregorianCalendar.MINUTE) + ':' + cal.get(GregorianCalendar.SECOND) + assemblerClass + descriptions); } } else if (action.equals(ACTION_DELETE_VALUE)) { String filename = req.getParameter(FILENAME_PARAM_NAME); if (filename == null || filename.length() == 0) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { File f = new File(destinationDir, filename); if (!f.exists() || f.isDirectory()) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } f.delete(); resp.setStatus(HttpServletResponse.SC_OK); } } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:cx.fbn.nevernote.sql.REnSearch.java
public int dateCheck(String date, long noteDate) throws java.lang.NumberFormatException { int offset = 0; boolean found = false; GregorianCalendar calendar = new GregorianCalendar(); if (date.contains("-")) { String modifier = date.substring(date.indexOf("-") + 1); offset = new Integer(modifier); offset = 0 - offset;//from ww w. j av a 2 s .co m date = date.substring(0, date.indexOf("-")); } if (date.contains("+")) { String modifier = date.substring(date.indexOf("+") + 1); offset = new Integer(modifier); date = date.substring(0, date.indexOf("+")); } if (date.equalsIgnoreCase("today")) { calendar.add(Calendar.DATE, offset); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 1); found = true; } if (date.equalsIgnoreCase("month")) { calendar.add(Calendar.MONTH, offset); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 1); found = true; } if (date.equalsIgnoreCase("year")) { calendar.add(Calendar.YEAR, offset); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 1); found = true; } if (date.equalsIgnoreCase("week")) { calendar.add(Calendar.DATE, 0 - calendar.get(Calendar.DAY_OF_WEEK) + 1); calendar.add(Calendar.DATE, (offset * 7)); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 1); found = true; } // If nothing was found, then we have a date number if (!found) { calendar = stringToGregorianCalendar(date); } String dateTimeFormat = new String("yyyyMMdd-HHmmss"); SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat); StringBuilder creationDate = new StringBuilder(simple.format(noteDate)); GregorianCalendar nCalendar = stringToGregorianCalendar(creationDate.toString().replace("-", "T")); if (calendar == null || nCalendar == null) // If we have something invalid, it automatically fails return 1; return calendar.compareTo(nCalendar); }
From source file:org.eevolution.form.VSCRP.java
public CategoryDataset createWeightDataset(Timestamp start, MResource r) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);/*from ww w . java 2 s . c om*/ gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id ) )From mpc_order mo Where ad_client_id=?", r.getAD_Client_ID()); // fjviejo e-evolution machineqty capacidad por el numero de maquinas // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID()); double dailyCapacity = DB.getSQLValue(null, "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID()); System.out.println("***** Capacidad diaria " + dailyCapacity); // e-evolution end double utilization = DB.getSQLValue(null, "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID()); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }