List of usage examples for java.util SimpleTimeZone setEndRule
public void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime)
From source file:Main.java
public static void main(String args[]) { SimpleTimeZone stobj = new SimpleTimeZone(820, "GMT"); // checking the initial value System.out.println("Initial value : " + stobj); // setting end rule stobj.setEndRule(Calendar.MAY, 2, Calendar.TUESDAY, 3600000); // checking the new value System.out.println("New value : " + stobj); }
From source file:Main.java
public static void main(String args[]) { SimpleTimeZone stobj = new SimpleTimeZone(-28800000, "America/Los_Angeles", Calendar.AUGUST, 1, -Calendar.SUNDAY, 7200000, Calendar.DECEMBER, -1, Calendar.SUNDAY, 7200000, 3600000); // checking the initial value System.out.println("Initial value : " + stobj); // setting end rule stobj.setEndRule(Calendar.MAY, 2, Calendar.TUESDAY, 3600000); // checking the new value System.out.println("New value : " + stobj); }
From source file:edu.ucsb.nceas.ezid.test.EZIDServiceTest.java
/** Generate a timestamp for use in IDs. */ public static String generateTimeString() { StringBuffer guid = new StringBuffer(); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime);/*www. jav a 2 s . c om*/ guid.append(calendar.get(Calendar.YEAR)); guid.append(calendar.get(Calendar.DAY_OF_YEAR)); guid.append(calendar.get(Calendar.HOUR_OF_DAY)); guid.append(calendar.get(Calendar.MINUTE)); guid.append(calendar.get(Calendar.SECOND)); guid.append(calendar.get(Calendar.MILLISECOND)); double random = Math.random(); guid.append(random); return guid.toString(); }
From source file:edu.harvard.iq.dvn.core.doi.DOIEZIdServiceBean.java
public static String generateYear() { StringBuffer guid = new StringBuffer(); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime);/* w ww .j a va 2s . com*/ guid.append(calendar.get(Calendar.YEAR)); return guid.toString(); }
From source file:edu.harvard.iq.dvn.core.doi.DOIEZIdServiceBean.java
public static String generateTimeString() { StringBuffer guid = new StringBuffer(); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime);//from w ww . j av a 2 s . com guid.append(calendar.get(Calendar.YEAR)); guid.append(calendar.get(Calendar.DAY_OF_YEAR)); guid.append(calendar.get(Calendar.HOUR_OF_DAY)); guid.append(calendar.get(Calendar.MINUTE)); guid.append(calendar.get(Calendar.SECOND)); guid.append(calendar.get(Calendar.MILLISECOND)); double random = Math.random(); guid.append(random); return guid.toString(); }
From source file:srvmonitor.thGetAgendas.java
@Override public void run() { /*//w ww. j ava 2s . com Recupera Parametros Fecha Actual */ logger.info("Buscando Agendas Activas"); String[] ids = TimeZone.getAvailableIDs(-4 * 60 * 60 * 1000); String clt = ids[0]; SimpleTimeZone tz = new SimpleTimeZone(-4 * 60 * 60 * 1000, clt); tz.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); tz.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(tz); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); // Jan = 0, dec = 11 int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH); int hour = calendar.get(Calendar.HOUR); // 12 hour clock int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); // 24 hour clock int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); int millisecond = calendar.get(Calendar.MILLISECOND); int findHour = 12; int findMinutes = 5; /* calendar.add(Calendar.HOUR_OF_DAY, -1); int hourBefore = calendar.get(Calendar.HOUR_OF_DAY); calendar.add(Calendar.HOUR_OF_DAY, 2); int hourAfter = calendar.get(Calendar.HOUR_OF_DAY); */ String posmonth = String.valueOf(month + 1); String posdayOfMonth = String.valueOf(dayOfMonth); String posdayOfWeek = String.valueOf(dayOfWeek); String posweekOfYear = String.valueOf(weekOfYear); String posweekOfMonth = String.valueOf(weekOfMonth); String poshourOfDay = String.valueOf(hourOfDay); String posminute = String.valueOf(minute); String possecond = String.valueOf(second); String posmillisecond = String.valueOf(millisecond); Calendar iteratorCalendar; String vSQL; String iteratorHour; String iteratorMinute; Statement stm; JSONObject jData; JSONObject jDataMinute; JSONArray jArray = new JSONArray(); JSONArray jArrayMinute = new JSONArray(); String posIteratorHour; String posIteratorMinute; /* Inicializa Lista de Agendas */ gDatos.getLstShowAgendas().clear(); gDatos.getLstActiveAgendas().clear(); for (int i = -findHour; i <= findHour; i++) { iteratorCalendar = new GregorianCalendar(tz); iteratorCalendar.add(Calendar.HOUR_OF_DAY, i); iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY)); posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1); vSQL = "select " + iteratorHour + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where " + " ageEnable=1 " + " and substr(month," + posmonth + ",1) = '1'" + " and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + " and substr(dayOfWeek," + posdayOfWeek + ",1) = '1'" + " and substr(weekOfYear," + posweekOfYear + ",1) = '1'" + " and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + " and substr(hourOfDay," + posIteratorHour + ",1) = '1'"; logger.debug("i: " + i + " vSQL: " + vSQL); try { stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); jData = new JSONObject(); ResultSet rs = stm.executeQuery(vSQL); if (rs != null) { while (rs.next()) { jData = new JSONObject(); jData.put("horaAgenda", rs.getString("horaAgenda")); jData.put("ageID", rs.getString("ageID")); jData.put("month", rs.getString("month")); jData.put("dayOfMonth", rs.getString("dayOfMonth")); jData.put("weekOfYear", rs.getString("weekOfYear")); jData.put("weekOfMonth", rs.getString("weekOfMonth")); jData.put("hourOfDay", rs.getString("hourOfDay")); jArray.put(jData); gDatos.getLstShowAgendas().add(jData); } } else { jData.put("horaAgenda", iteratorHour); jData.put("ageID", ""); jData.put("month", ""); jData.put("dayOfMonth", ""); jData.put("weekOfYear", ""); jData.put("weekOfMonth", ""); jData.put("hourOfDay", ""); jArray.put(jData); gDatos.getLstShowAgendas().add(jData); System.out.println("No hay registros"); } stm.close(); } catch (SQLException | JSONException e) { logger.error(e.getMessage()); } } iteratorCalendar = new GregorianCalendar(tz); iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY)); posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1); for (int i = -findMinutes; i <= 0; i++) { iteratorCalendar = new GregorianCalendar(tz); iteratorCalendar.add(Calendar.MINUTE, i); iteratorMinute = String.valueOf(iteratorCalendar.get(Calendar.MINUTE)); posIteratorMinute = String.valueOf(Integer.valueOf(iteratorMinute) + 1); vSQL = "select " + iteratorMinute + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where " + " ageEnable=1 " + " and substr(month," + posmonth + ",1) = '1'" + " and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + " and substr(dayOfWeek," + posdayOfWeek + ",1) = '1'" + " and substr(weekOfYear," + posweekOfYear + ",1) = '1'" + " and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + " and substr(hourOfDay," + posIteratorHour + ",1) = '1'" + " and substr(minute," + posIteratorMinute + ",1) = '1'"; logger.debug("i: " + i + " vSQL: " + vSQL); try { stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stm.executeQuery(vSQL); if (rs != null) { while (rs.next()) { jDataMinute = new JSONObject(); jDataMinute.put("horaAgenda", rs.getString("horaAgenda")); jDataMinute.put("ageID", rs.getString("ageID")); jDataMinute.put("month", rs.getString("month")); jDataMinute.put("dayOfMonth", rs.getString("dayOfMonth")); jDataMinute.put("weekOfYear", rs.getString("weekOfYear")); jDataMinute.put("weekOfMonth", rs.getString("weekOfMonth")); jDataMinute.put("hourOfDay", rs.getString("hourOfDay")); jArrayMinute.put(jDataMinute); gDatos.getLstActiveAgendas().add(jDataMinute); } } stm.close(); } catch (SQLException | JSONException e) { logger.error(e.getMessage()); } } for (int i = 0; i < gDatos.getLstShowAgendas().size(); i++) { logger.debug(gDatos.getLstShowAgendas().get(i).toString()); } for (int i = 0; i < gDatos.getLstActiveAgendas().size(); i++) { logger.debug(gDatos.getLstActiveAgendas().get(i).toString()); } logger.info("Finaliza busquenda agendas activas..."); }
From source file:edu.ucsb.nceas.metacattest.UploadIPCCDataTest.java
private String generateId() { int version = 1; StringBuffer docid = new StringBuffer(DATAIDPREFIX); docid.append(DOT);/*from ww w .j a v a 2s. c o m*/ // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime); int time = 0; docid.append(calendar.get(Calendar.YEAR)); time = calendar.get(Calendar.DAY_OF_YEAR); if (time < 10) { docid.append("0"); docid.append("0"); docid.append(time); } else if (time < 100) { docid.append("0"); docid.append(time); } else { docid.append(time); } time = calendar.get(Calendar.HOUR_OF_DAY); if (time < 10) { docid.append("0"); docid.append(time); } else { docid.append(time); } time = calendar.get(Calendar.MINUTE); if (time < 10) { docid.append("0"); docid.append(time); } else { docid.append(time); } time = calendar.get(Calendar.SECOND); if (time < 10) { docid.append("0"); docid.append(time); } else { docid.append(time); } //sometimes this number is not unique, so we append a random number int random = (new Double(Math.random() * 100)).intValue(); docid.append(random); docid.append(DOT); docid.append(version); return docid.toString(); }
From source file:edu.ucsb.nceas.MCTestCase.java
/** * Create a unique docid for testing insert and update. Does not * include the 'revision' part of the id. * /* w ww. j av a 2s. c o m*/ * @return a String docid based on the current date and time */ protected String generateDocumentId() { try { Thread.sleep(1010); } catch (InterruptedException ie) { debug("Could not sleep: " + ie.getMessage()); } StringBuffer docid = new StringBuffer(prefix); docid.append("."); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime); docid.append(calendar.get(Calendar.YEAR)); docid.append(calendar.get(Calendar.DAY_OF_YEAR)); docid.append(calendar.get(Calendar.HOUR_OF_DAY)); docid.append(calendar.get(Calendar.MINUTE)); docid.append(calendar.get(Calendar.SECOND)); return docid.toString(); }
From source file:com.lastsoft.plog.adapter.GameAdapter.java
public void playPopup(View v, final int position) { try {//www . j a v a 2 s .com InputMethodManager inputManager = (InputMethodManager) mActivity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } catch (Exception ignored) { } PopupMenu popup = new PopupMenu(mActivity, v); MenuInflater inflater = popup.getMenuInflater(); if (games.get(position).expansionFlag == true) { inflater.inflate(R.menu.game_expansion_overflow, popup.getMenu()); } else { inflater.inflate(R.menu.game_overflow, popup.getMenu()); } if (games.get(position).gameBGGID == null || games.get(position).gameBGGID.equals("")) { popup.getMenu().removeItem(R.id.update_bgg); popup.getMenu().removeItem(R.id.open_bgg); popup.getMenu().removeItem(R.id.add_bgg); } if (games.get(position).gameBoxImage == null || games.get(position).gameBoxImage.equals("")) { popup.getMenu().removeItem(R.id.view_box_photo); } if (games.get(position).taggedToPlay <= 0) { popup.getMenu().removeItem(R.id.remove_bucket_list); } else { popup.getMenu().removeItem(R.id.add_bucket_list); } SharedPreferences app_preferences; app_preferences = PreferenceManager.getDefaultSharedPreferences(mActivity); long currentDefaultPlayer = app_preferences.getLong("defaultPlayer", -1); if (games.get(position).collectionFlag || currentDefaultPlayer == -1) { popup.getMenu().removeItem(R.id.add_bgg); } //check if this game has been played //if so, can't delete if (GamesPerPlay.hasGameBeenPlayed(games.get(position))) { popup.getMenu().removeItem(R.id.delete_game); } popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.delete_game: ((MainActivity) mActivity).deleteGame(games.get(position).getId()); return true; case R.id.add_tenbyten: ((MainActivity) mActivity).addToTenXTen(games.get(position).getId()); return true; case R.id.view_plays: if (games.get(position).expansionFlag == true) { ((MainActivity) mActivity).openPlays(games.get(position).gameName, false, 9, fragmentName, currentYear); } else { ((MainActivity) mActivity).openPlays(games.get(position).gameName, false, 0, fragmentName, currentYear); } return true; case R.id.open_bgg: Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://bgg.cc/boardgame/" + games.get(position).gameBGGID)); mActivity.startActivity(browserIntent); return true; case R.id.update_bgg: mPosition = position; if (games.get(position).expansionFlag == true) { ((MainActivity) mActivity).searchGameViaBGG(games.get(position).gameName, false, true, -1); } else { ((MainActivity) mActivity).searchGameViaBGG(games.get(position).gameName, false, false, -1); } return true; case R.id.add_bgg: mPosition = position; ((MainActivity) mActivity).updateGameViaBGG(games.get(position).gameName, games.get(position).gameBGGID, "", true, false); return true; case R.id.add_box_photo: ((GamesFragment) mFragment).captureBox(games.get(position)); return true; case R.id.view_box_photo: String[] photoParts = games.get(position).gameBoxImage.split("/"); File newFile = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Plog/", photoParts[photoParts.length - 1]); Uri contentUri = FileProvider.getUriForFile(mActivity.getApplicationContext(), "com.lastsoft.plog.fileprovider", newFile); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(contentUri, "image/*"); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); mActivity.startActivity(intent); return true; case R.id.add_bucket_list: String[] ids = TimeZone.getAvailableIDs(-5 * 60 * 60 * 1000); // if no ids were returned, something is wrong. get out. //if (ids.length == 0) // System.exit(0); // begin output //System.out.println("Current Time"); // create a Eastern Standard Time time zone SimpleTimeZone pdt = new SimpleTimeZone(-5 * 60 * 60 * 1000, ids[0]); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); // create a GregorianCalendar with the Pacific Daylight time zone // and the current date and time Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime); int i = (int) (calendar.getTime().getTime() / 1000); games.get(position).taggedToPlay = i; games.get(position).save(); Snackbar.make(((GamesFragment) mFragment).mCoordinatorLayout, games.get(position).gameName + mActivity.getString(R.string.added_to_bl), Snackbar.LENGTH_LONG) .setAction(mActivity.getString(R.string.undo), new View.OnClickListener() { @Override public void onClick(View view) { games.get(position).taggedToPlay = 0; games.get(position).save(); if (playListType == 2) { ((MainActivity) mActivity).onFragmentInteraction("refresh_games"); } } }).show(); // Do not forget to show! return true; case R.id.remove_bucket_list: final int taggedToPlay = games.get(position).taggedToPlay; final Game gameToUndo = games.get(position); games.get(position).taggedToPlay = 0; games.get(position).save(); Snackbar.make(((GamesFragment) mFragment).mCoordinatorLayout, games.get(position).gameName + mActivity.getString(R.string.removed_from_bl), Snackbar.LENGTH_LONG) .setAction(mActivity.getString(R.string.undo), new View.OnClickListener() { @Override public void onClick(View view) { gameToUndo.taggedToPlay = taggedToPlay; gameToUndo.save(); if (playListType == 2) { ((MainActivity) mActivity).onFragmentInteraction("refresh_games"); } } }).show(); // Do not forget to show! if (playListType == 2) { ((MainActivity) mActivity).onFragmentInteraction("refresh_games"); } return true; default: return false; } } } ); popup.show(); }
From source file:org.apache.jena.graph.test.TestTypedLiterals.java
public void testDateTime_18() { SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "America/Los_Angeles"); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); // create a GregorianCalendar with the Pacific Daylight time zone Calendar ncal = new GregorianCalendar(pdt); ncal.set(2004, 02, 21, 12, 50, 42);//before daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); Literal l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-03-21T20:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); ncal = new GregorianCalendar(pdt); ncal.set(2004, 03, 21, 12, 50, 42);//within daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); l1 = m.createTypedLiteral(ncal);// w ww.j a v a 2s . c o m assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-04-21T19:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); }