List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:edu.missouri.bas.service.SensorService.java
protected void writeLocationToFile(Location l) { String toWrite;/*from w ww . ja va 2s . c o m*/ Calendar cl = Calendar.getInstance(); SimpleDateFormat curFormater = new SimpleDateFormat("MMMMM_dd"); String dateObj = curFormater.format(cl.getTime()); File f = new File(BASE_PATH, "locations." + bluetoothMacAddress + "." + dateObj + ".txt"); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("US/Central")); toWrite = String.valueOf(cal.getTime()) + "," + l.getLatitude() + "," + l.getLongitude() + "," + l.getAccuracy() + "," + l.getProvider() + "," + getNameFromType(currentUserActivity); if (f != null) { try { writeToFile(f, toWrite); //sendDatatoServer("locations."+bluetoothMacAddress+"."+dateObj,toWrite); //Ricky TransmitData transmitData = new TransmitData(); transmitData.execute("locations." + bluetoothMacAddress + "." + dateObj, toWrite); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.globus.workspace.cloud.client.util.CumulusParameterConvert.java
private void s3ObjToFileList(ArrayList files, S3Object[] s3Objs, boolean rw, S3Service s3Service) throws ExecutionProblem { Calendar cal = Calendar.getInstance(); for (int i = 0; i < s3Objs.length; i++) { String name = s3Objs[i].getKey(); name = this.stripKey(name); if (name != null) { Date dt = s3Objs[i].getLastModifiedDate(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(dt.getTime()); FileListing fl = new FileListing(); fl.setName(name);/*w ww. j av a 2 s . c om*/ fl.setSize(s3Objs[i].getContentLength()); fl.setDate(convertDate(cal)); fl.setTime(convertTime(cal)); fl.setDirectory(false); fl.setReadWrite(rw); fl.setOwner(s3Objs[i].getOwner().getDisplayName()); String desc = this.s3DownloadImageDescription(name, rw, s3Service); fl.setDescription(desc); files.add(fl); } } }
From source file:edu.hawaii.soest.kilonalu.utilities.FileSource.java
/** * A method that executes the reading of data from the data file to the RBNB * server after all configuration of settings, connections to hosts, and * thread initiatizing occurs. This method contains the detailed code for * reading the data and interpreting the data files. */// w ww . j av a2 s . co m protected boolean execute() { logger.debug("FileSource.execute() called."); boolean failed = true; // indicates overall success of execute() // do not execute the stream if there is no connection if (!isConnected()) return false; try { // open the data file for monitoring FileReader reader = new FileReader(new File(getFileName())); this.fileReader = new BufferedReader(reader); // add channels of data that will be pushed to the server. // Each sample will be sent to the Data Turbine as an rbnb frame. int channelIndex = 0; ChannelMap rbnbChannelMap = new ChannelMap(); // used to insert channel data ChannelMap registerChannelMap = new ChannelMap(); // used to register channels // add the DecimalASCIISampleData channel to the channelMap channelIndex = registerChannelMap.Add(getRBNBChannelName()); registerChannelMap.PutUserInfo(channelIndex, "units=none"); // and register the RBNB channels getSource().Register(registerChannelMap); registerChannelMap.Clear(); // on execute(), query the DT to find the timestamp of the last sample inserted // and be sure the following inserts are after that date ChannelMap requestMap = new ChannelMap(); int entryIndex = requestMap.Add(getRBNBClientName() + "/" + getRBNBChannelName()); logger.debug("Request Map: " + requestMap.toString()); Sink sink = new Sink(); sink.OpenRBNBConnection(getServer(), "lastEntrySink"); sink.Request(requestMap, 0., 1., "newest"); ChannelMap responseMap = sink.Fetch(5000); // get data within 5 seconds // initialize the last sample date Date initialDate = new Date(); long lastSampleTimeAsSecondsSinceEpoch = initialDate.getTime() / 1000L; logger.debug("Initialized the last sample date to: " + initialDate.toString()); logger.debug("The last sample date as a long is: " + lastSampleTimeAsSecondsSinceEpoch); if (responseMap.NumberOfChannels() == 0) { // set the last sample time to 0 since there are no channels yet lastSampleTimeAsSecondsSinceEpoch = 0L; logger.debug("Resetting the last sample date to the epoch: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L)).toString()); } else if (responseMap.NumberOfChannels() > 0) { lastSampleTimeAsSecondsSinceEpoch = new Double(responseMap.GetTimeStart(entryIndex)).longValue(); logger.debug("There are existing channels. Last sample time: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L)).toString()); } sink.CloseRBNBConnection(); // poll the data file for new lines of data and insert them into the RBNB while (true) { String line = fileReader.readLine(); if (line == null) { this.streamingThread.sleep(POLL_INTERVAL); } else { // test the line for the expected data pattern Matcher matcher = this.dataPattern.matcher(line); // if the line matches the data pattern, insert it into the DataTurbine if (matcher.matches()) { logger.debug("This line matches the data line pattern: " + line); Date sampleDate = getSampleDate(line); if (this.dateFormats == null || this.dateFields == null) { logger.warn("Using the default datetime format and field for sample data. " + "Use the -f and -d options to explicitly set date time fields."); } logger.debug("Sample date is: " + sampleDate.toString()); // convert the sample date to seconds since the epoch long sampleTimeAsSecondsSinceEpoch = (sampleDate.getTime() / 1000L); // only insert samples newer than the last sample seen at startup // and that are not in the future (> 1 hour since the CTD clock // may have drifted) Calendar currentCal = Calendar.getInstance(); this.tz = TimeZone.getTimeZone(this.timezone); currentCal.setTimeZone(this.tz); currentCal.add(Calendar.HOUR, 1); Date currentDate = currentCal.getTime(); if (lastSampleTimeAsSecondsSinceEpoch < sampleTimeAsSecondsSinceEpoch && sampleTimeAsSecondsSinceEpoch < currentDate.getTime() / 1000L) { // add the sample timestamp to the rbnb channel map //registerChannelMap.PutTime(sampleTimeAsSecondsSinceEpoch, 0d); rbnbChannelMap.PutTime((double) sampleTimeAsSecondsSinceEpoch, 0d); // then add the data line to the channel map channelIndex = rbnbChannelMap.Add(getRBNBChannelName()); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, line + "\r\n"); // be sure we are connected int numberOfChannelsFlushed = 0; try { //insert into the DataTurbine numberOfChannelsFlushed = getSource().Flush(rbnbChannelMap, true); // in the event we just lost the network, sleep, try again while (numberOfChannelsFlushed < 1) { logger.debug("No channels flushed, trying again in 10 seconds."); Thread.sleep(10000L); numberOfChannelsFlushed = getSource().Flush(rbnbChannelMap, true); } } catch (SAPIException sapie) { // reconnect if an exception is thrown on Flush() logger.debug("Error while flushing the source: " + sapie.getMessage()); logger.debug("Disconnecting from the DataTurbine."); disconnect(); logger.debug("Connecting to the DataTurbine."); connect(); getSource().Flush(rbnbChannelMap); // in the event we just lost the network, sleep, try again while (numberOfChannelsFlushed < 1) { logger.debug("No channels flushed, trying again in 10 seconds."); Thread.sleep(10000L); numberOfChannelsFlushed = getSource().Flush(rbnbChannelMap, true); } } // reset the last sample time to the sample just inserted lastSampleTimeAsSecondsSinceEpoch = sampleTimeAsSecondsSinceEpoch; logger.debug("Last sample time is now: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L).toString())); logger.info(getRBNBClientName() + " Sample sent to the DataTurbine: " + line.trim()); rbnbChannelMap.Clear(); } else { logger.info("The current line is earlier than the last entry " + "in the Data Turbine or is a date in the future. " + "Skipping it. The line was: " + line); } } else { logger.info("The current line doesn't match an expected " + "data line pattern. Skipping it. The line was: " + line); } } // end if() } // end while } catch (ParseException pe) { logger.info( "There was a problem parsing the sample date string. " + "The message was: " + pe.getMessage()); try { this.fileReader.close(); } catch (IOException ioe2) { logger.info( "There was a problem closing the data file. The " + "message was: " + ioe2.getMessage()); } failed = true; return !failed; } catch (SAPIException sapie) { logger.info("There was a problem communicating with the DataTurbine. " + "The message was: " + sapie.getMessage()); try { this.fileReader.close(); } catch (IOException ioe2) { logger.info( "There was a problem closing the data file. The " + "message was: " + ioe2.getMessage()); } failed = true; return !failed; } catch (InterruptedException ie) { logger.info( "There was a problem while polling the data file. The " + "message was: " + ie.getMessage()); try { this.fileReader.close(); } catch (IOException ioe2) { logger.info( "There was a problem closing the data file. The " + "message was: " + ioe2.getMessage()); } failed = true; return !failed; } catch (IOException ioe) { logger.info("There was a problem opening the data file. " + "The message was: " + ioe.getMessage()); failed = true; return !failed; } }
From source file:io.realm.RealmJsonTests.java
@Test public void createObjectFromJson_dateAsStringTimeZone() throws JSONException { // Oct 03 2015 14:45.33 JSONObject json = new JSONObject(); json.put("columnDate", "/Date(1443854733376+0800)/"); realm.beginTransaction();/*w w w . j av a 2s . com*/ realm.createObjectFromJson(AllTypes.class, json); realm.commitTransaction(); AllTypes obj = realm.allObjects(AllTypes.class).first(); Calendar cal = GregorianCalendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Australia/West")); cal.set(2015, Calendar.OCTOBER, 03, 14, 45, 33); cal.set(Calendar.MILLISECOND, 0); Date convDate = obj.getColumnDate(); assertEquals(convDate.getTime(), cal.getTime().getTime()); }
From source file:io.realm.RealmJsonTests.java
@Test public void createObjectFromJson_streamDateAsISO8601String() throws IOException { InputStream in = TestHelper.loadJsonFromAssets(context, "date_as_iso8601_string.json"); realm.beginTransaction();//from w w w . jav a2 s. com realm.createObjectFromJson(AllTypes.class, in); realm.commitTransaction(); in.close(); Calendar cal = new GregorianCalendar(2007, 8 - 1, 13, 19, 51, 23); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.set(Calendar.MILLISECOND, 789); Date date = cal.getTime(); cal.set(Calendar.MILLISECOND, 0); Date dateZeroMillis = cal.getTime(); // Check that all primitive types are imported correctly AllTypes obj = realm.allObjects(AllTypes.class).first(); assertEquals(dateZeroMillis, obj.getColumnDate()); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testParseZone() throws ParseException { final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US); cal.clear();//from w w w . ja v a 2 s.com cal.set(2003, Calendar.JULY, 10, 16, 33, 20); final DateParser fdf = getInstance(yMdHmsSZ, NEW_YORK, Locale.US); assertEquals(cal.getTime(), fdf.parse("2003-07-10T15:33:20.000 -0500")); assertEquals(cal.getTime(), fdf.parse("2003-07-10T15:33:20.000 GMT-05:00")); assertEquals(cal.getTime(), fdf.parse("2003-07-10T16:33:20.000 Eastern Daylight Time")); assertEquals(cal.getTime(), fdf.parse("2003-07-10T16:33:20.000 EDT")); cal.setTimeZone(TimeZone.getTimeZone("GMT-3")); cal.set(2003, Calendar.FEBRUARY, 10, 9, 0, 0); assertEquals(cal.getTime(), fdf.parse("2003-02-10T09:00:00.000 -0300")); cal.setTimeZone(TimeZone.getTimeZone("GMT+5")); cal.set(2003, Calendar.FEBRUARY, 10, 15, 5, 6); assertEquals(cal.getTime(), fdf.parse("2003-02-10T15:05:06.000 +0500")); }
From source file:de.ribeiro.android.gso.dataclasses.Pager.java
/** * * Erzeugt aus dem WeekData-Objekt eine List aus TimeTableViewObject * * @param weekData//from ww w . j a va2s . co m * @param currentDay * @return * @author Tobias Janssen */ private List<TimetableViewObject> createTimetableDayViewObject(WeekData weekData, Calendar currentDay) { List<TimetableViewObject> result = new ArrayList<TimetableViewObject>(); List<Lesson> schulstunden = GetSchulstunden(); currentDay.setTimeZone(TimeZone.getTimeZone("UTC")); // leeren Stundenplan erstellen for (int std = 0; std < schulstunden.size(); std++) { result.add(new TimetableViewObject(timeslots[std + 1], "", "#000000")); } boolean nothingAdded = true; // alle events durchgehen for (int i = 0; i < weekData.events.size(); i++) { ICalEvent event = weekData.events.get(i); // prfen, ob event im gewnschten Jahr und tag ist if (event.DTSTART.get(Calendar.YEAR) == currentDay.get(Calendar.YEAR) && event.DTSTART.get(Calendar.DAY_OF_YEAR) == currentDay.get(Calendar.DAY_OF_YEAR)) { // ja, dann schulstunde des events herausfinden Time st = new Time(); st.set(event.DTSTART.getTimeInMillis()); int start = GetSchulstundeOfDateTime(st); Time et = new Time(); et.set(event.DTEND.getTimeInMillis() - 60000); int end = GetSchulstundeOfDateTime(et); // ende der schulstunde herausfinden if (start != -1) { for (int h = start; h <= end; h++) { nothingAdded = false; if (result.get(h).row2 == "") { if (event.UID.equalsIgnoreCase("deleted")) { result.set(h, new TimetableViewObject(timeslots[h + 1], "---" + " --- " + " --- ", "#FF0000")); } else { String color = "#000000"; if (event.UID.equalsIgnoreCase("diff")) color = "#FF0000"; if (weekData.typeId.equalsIgnoreCase("4")) { result.set(h, new TimetableViewObject(timeslots[h + 1], event.DESCRIPTION + " " + event.SUMMARY, color)); } else { result.set(h, new TimetableViewObject(timeslots[h + 1], event.DESCRIPTION.replace(weekData.elementId, "") + " " + event.SUMMARY + " " + event.LOCATION, color)); } } } else { // Stundendoppelbelegung if (weekData.typeId.equalsIgnoreCase("4")) { result.get(h).row2 += "\r\n" + event.DESCRIPTION + " " + event.SUMMARY + " "; } else { result.get(h).row2 += "\r\n" + event.DESCRIPTION.replace(weekData.elementId, "") + " " + event.SUMMARY + " " + event.LOCATION; } } } } else _logger.Error("No matching lesson hour for event found " + event.DTSTART.getTime()); } } if (hideEmptyHours) { int i = 0; boolean done = false; while (!done) { if (i < result.size()) { if (result.get(i).row2.equalsIgnoreCase("")) { result.remove(i); } else { i++; } } else done = true; } } // prfen, ob gar keine Stunden vorhanden sind if (nothingAdded) { result.clear(); result.add(new TimetableViewObject("", "kein Unterricht", "#000000")); } return result; }
From source file:com.sonyericsson.jenkins.plugins.bfa.db.MongoDBKnowledgeBase.java
/** * Generates a {@link TimePeriod} based on a MongoDB grouping aggregation result. * @param result the result to interpret * @param intervalSize the interval size, should be set to Calendar.HOUR_OF_DAY, * Calendar.DATE or Calendar.MONTH.// w w w . ja va 2s. c o m * @return TimePeriod */ private TimePeriod generateTimePeriodFromResult(DBObject result, int intervalSize) { BasicDBObject groupedAttrs = (BasicDBObject) result.get("_id"); int month = groupedAttrs.getInt("month"); int year = groupedAttrs.getInt("year"); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month - 1); // MongoDB timezone is UTC: c.setTimeZone(new SimpleTimeZone(0, "UTC")); TimePeriod period = null; if (intervalSize == Calendar.HOUR_OF_DAY) { int dayOfMonth = groupedAttrs.getInt("dayOfMonth"); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); int hour = groupedAttrs.getInt("hour"); c.set(Calendar.HOUR_OF_DAY, hour); period = new Hour(c.getTime()); } else if (intervalSize == Calendar.DATE) { int dayOfMonth = groupedAttrs.getInt("dayOfMonth"); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); period = new Day(c.getTime()); } else { period = new Month(c.getTime()); } return period; }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
/** * Method used to compute date time text to desired date time text. * <ol>/*from w w w . java 2 s . c o m*/ * <li>Input Format: Feb 02, 2014 11:00 PM PST</li> * <li>Output Format : Thu, Jan 9, 2014 11:00 PM - Fri, Jan 10, 2014 12:00 * AM PST</li> * </ol> * * @param dateTimeText * (date and time in text format) * @return expectedDateTimeText */ public String computeDateTimeForRecurringWebinar(final String dateTimeText) { // Convert date time string to date time object and get the start & end // day of month. String timeZone = this.propertyUtil.getProperty("environment.timezone"); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone(timeZone)); Date startDate = this.convertDateTextToObject( this.messages.getMessage("manageWebinar.date.format.individualSession.start", null, this.locale), dateTimeText, timeZone); c.setTime(startDate); String startDayOfMonth = this.convertDateObjectToText( this.messages.getMessage("date.format.registrant.start.long.formatted", null, this.locale), c.getTime(), timeZone); c.add(Calendar.HOUR_OF_DAY, 1); Date endDate = c.getTime(); String endDayOfMonth = this.convertDateObjectToText( this.messages.getMessage("date.format.registrant.start.long.formatted", null, this.locale), endDate, timeZone); // Convert start date time object to desired string format. String formattedStartDate = this.convertDateObjectToText( this.messages.getMessage("manageWebinar.date.format.startAndEndDate.start", null, this.locale), startDate, timeZone); // condition to check whether end date fall in same day or another day // and pick date format accordingly and convert end date to string // format String formattedEndDate = ""; if (Integer.parseInt(startDayOfMonth) != Integer.parseInt(endDayOfMonth)) { formattedEndDate = this.convertDateObjectToText(this.messages.getMessage( "manageWebinar.date.format.startAndEndDate.diffDay.end", null, this.locale), endDate, timeZone); } else { formattedEndDate = this.convertDateObjectToText(this.messages.getMessage( "manageWebinar.date.format.startAndEndDate.sameDay.end", null, this.locale), endDate, timeZone); } // Get the expected date and time in string format. String expectedDateTimeText = formattedStartDate.trim() + " - " + formattedEndDate; return expectedDateTimeText; }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
/** * Method used to get expected date format based on the date time text in * manage webinar page.// w w w . j a va 2s . com * <ol> * <li>Input Format: Fri, Jan 10, 2014 9:00 PM - 10:00 PM PST</li> * <li>Input Format : Thu, Jan 9, 2014 11:00 PM - Fri, Jan 10, 2014 12:00 AM * PST</li> * <li>Output Format: Friday, January 10, 2014 12:00 AM - 1:00 AM PST</li> * <li>Output Format: Thursday, January 9, 2014 11:00 PM - Friday, January * 10, 2014 12:00 AM PST</li> * </ol> * * @param dateTimeText * (date and time in text format) * @return expectedDateTimeText */ public String getDateTimeAsText(final String dateTimeText) { int timeZonePosition = dateTimeText.lastIndexOf(" "); String timeZoneText = dateTimeText.substring(timeZonePosition + 1); // Split date time string to construct desired format. String[] dateTimeArray = dateTimeText.split("-"); // Convert date time string to date time object and get the start day // of month. String timeZone = this.propertyUtil.getProperty("environment.timezone"); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone(timeZone)); Date startDate = this.convertDateTextToObject(this.messages .getMessage("manageWebinar.date.format.startAndEndDate.short.start", null, this.locale), dateTimeArray[0].trim() + " " + timeZoneText, timeZone); c.setTime(startDate); String startDayOfMonth = this.convertDateObjectToText( this.messages.getMessage("date.format.registrant.start.long.formatted", null, this.locale), c.getTime(), timeZone); Date endDate = null; String endDayOfMonth = startDayOfMonth; if (dateTimeArray[1].trim().length() > 12) { endDate = this.convertDateTextToObject(this.messages .getMessage("manageWebinar.date.format.startAndEndDate.diffDay.end", null, this.locale), dateTimeArray[1].trim(), timeZone); endDayOfMonth = this.convertDateObjectToText( this.messages.getMessage("date.format.registrant.start.long.formatted", null, this.locale), endDate, timeZone); } // Convert start date time object to desired string format. String formattedStartDate = this.convertDateObjectToText( this.messages.getMessage("manageWebinar.date.format.startAndEndDate.long.start", null, this.locale), startDate, timeZone); // condition to check whether end date fall in same day or another day // and pick date format accordingly and convert end date to string // format String formattedEndDate = dateTimeArray[1].trim(); if (Integer.parseInt(startDayOfMonth) != Integer.parseInt(endDayOfMonth)) { formattedEndDate = this.convertDateObjectToText(this.messages .getMessage("manageWebinar.date.format.startAndEndDate.long.diffDay.end", null, this.locale), endDate, timeZone); } // Get the expected date and time in string format. String expectedDateTimeText = formattedStartDate + " - " + formattedEndDate; return expectedDateTimeText; }