List of usage examples for org.joda.time DateTime toCalendar
public Calendar toCalendar(Locale locale)
java.util.Calendar
, assigning exactly the same millisecond instant. From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the local calendar./*from w ww .j a v a 2 s. co m*/ * @param timeZone the time zone * @return the local calendar * @throws ParseException the parse exception */ public static Calendar getLocalCalendar(final String timeZone) throws ParseException { DateTime dateTime = new DateTime(DateTimeZone.forID(timeZone)); Calendar tzCalendar = dateTime.toCalendar(Locale.ENGLISH); return tzCalendar; }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Parses the to zone calendar./*from w w w . j ava 2 s . c o m*/ * @param timestamp the timestamp * @param pattern the pattern * @param timeZone the time zone * @return the calendar */ public static Calendar parseToZoneCalendar(String timestamp, String pattern, String timeZone) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); fmt = fmt.withZoneUTC(); DateTime dt = fmt.parseDateTime(timestamp); dt = dt.toDateTime(DateTimeZone.forID(timeZone)); return dt.toCalendar(Locale.ENGLISH); }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Format./* w ww . ja v a2 s .c o m*/ * @param timestamp the timestamp * @param pattern the pattern * @return the string */ public static Calendar parseToCalendar(String timestamp, String pattern) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); DateTime dt = fmt.parseDateTime(timestamp); return dt.toCalendar(Locale.ENGLISH); }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the UTC calendar.// w ww . j a v a 2 s .c om * @return the UTC calendar */ public static Calendar getUTCCalendar() { DateTime dt = new DateTime(DateTimeZone.UTC); Calendar utcCalendar = dt.toCalendar(Locale.ENGLISH); LOGGER.debug("Current UTC Date " + formatToUTC(utcCalendar, DATE_FMT_FULL_TZ)); return utcCalendar; }
From source file:com.enonic.cms.core.portal.datasource.handler.util.GetFormattedDateHandler.java
License:Open Source License
@Override protected Document handle(final DataSourceRequest req, final GetFormattedDateParams params) throws Exception { final int offset = params.offset; final String dateFormat = params.dateFormat; final String language = params.language; final String country = params.country; final Locale locale = new Locale(language, country); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, locale); final DateTime now = this.timeService.getNowAsDateTime(); return getFormattedDate(now.toCalendar(locale), offset, simpleDateFormat); }
From source file:com.microsoft.office365.snippetapp.Snippets.CalendarSnippets.java
License:MIT License
/** * Creates a recurring event. This snippet will create an event that recurs * every Tuesday and Thursday from 1PM to 2PM. You can modify this snippet * to work with other recurrence patterns. * * @param subject The subject of the event * @param itemBodyHtml The body of the event as HTML * @param attendees A list of attendee email addresses * @return String The id of the created event *///from ww w. ja va 2 s . c om public String createRecurringCalendarEvent(String subject, String itemBodyHtml, List<String> attendees) throws ExecutionException, InterruptedException { //Create a new Office 365 Event object Event newEvent = new Event(); newEvent.setSubject(subject); ItemBody itemBody = new ItemBody(); itemBody.setContent(itemBodyHtml); itemBody.setContentType(BodyType.HTML); newEvent.setBody(itemBody); //Set the attendee list List<Attendee> attendeeList = convertEmailStringsToAttendees(attendees); newEvent.setAttendees(attendeeList); //Set start date to the next occurring Tuesday DateTime startDate = DateTime.now(); if (startDate.getDayOfWeek() < DateTimeConstants.TUESDAY) { startDate = startDate.dayOfWeek().setCopy(DateTimeConstants.TUESDAY); } else { startDate = startDate.plusWeeks(1); startDate = startDate.dayOfWeek().setCopy(DateTimeConstants.TUESDAY); } //Set start time to 1 PM startDate = startDate.hourOfDay().setCopy(13).withMinuteOfHour(0).withSecondOfMinute(0) .withMillisOfSecond(0); //Set end time to 2 PM DateTime endDate = startDate.hourOfDay().setCopy(14); //Set start and end time on the new Event (next Tuesday 1-2PM) newEvent.setStart(startDate.toCalendar(Locale.getDefault())); newEvent.setIsAllDay(false); newEvent.setEnd(endDate.toCalendar(Locale.getDefault())); //Configure the recurrence pattern for the new event //In this case the meeting will occur every Tuesday and Thursday from 1PM to 2PM RecurrencePattern recurrencePattern = new RecurrencePattern(); List<DayOfWeek> daysMeetingRecursOn = new ArrayList(); daysMeetingRecursOn.add(DayOfWeek.Tuesday); daysMeetingRecursOn.add(DayOfWeek.Thursday); recurrencePattern.setType(RecurrencePatternType.Weekly); recurrencePattern.setDaysOfWeek(daysMeetingRecursOn); recurrencePattern.setInterval(1); //recurs every week //Create a recurring range. In this case the range does not end //and the event occurs every Tuesday and Thursday forever. RecurrenceRange recurrenceRange = new RecurrenceRange(); recurrenceRange.setType(RecurrenceRangeType.NoEnd); recurrenceRange.setStartDate(startDate.toCalendar(Locale.getDefault())); //Create a pattern of recurrence. It contains the recurrence pattern //and recurrence range created previously. PatternedRecurrence patternedRecurrence = new PatternedRecurrence(); patternedRecurrence.setPattern(recurrencePattern); patternedRecurrence.setRange(recurrenceRange); //Finally pass the patterned recurrence to the new Event object. newEvent.setRecurrence(patternedRecurrence); //Create the event and return the id return mCalendarClient.getMe().getEvents().select("ID").add(newEvent).get().getId(); }
From source file:com.netflix.ice.login.saml.Saml.java
License:Apache License
/** * Process an assertion and setup our session attributes *///from w ww .j a va 2s. c o m private void processAssertion(IceSession iceSession, Assertion assertion, LoginResponse lr) throws LoginMethodException { boolean foundAnAccount = false; iceSession.voidSession(); for (AttributeStatement as : assertion.getAttributeStatements()) { // iterate once to assure we set the username first for (Attribute attr : as.getAttributes()) { if (attr.getName().equals("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")) { for (XMLObject groupXMLObj : attr.getAttributeValues()) { String username = groupXMLObj.getDOM().getTextContent(); iceSession.setUsername(username); } } } // iterate again for everything else for (Attribute attr : as.getAttributes()) { if (attr.getName().equals("com.netflix.ice.account")) { for (XMLObject groupXMLObj : attr.getAttributeValues()) { String allowedAccount = groupXMLObj.getDOM().getTextContent(); if (allowedAccount.equals(config.allAccounts)) { whitelistAllAccounts(iceSession); foundAnAccount = true; logger.info("Found Allow All Accounts: " + allowedAccount); break; } else { if (whitelistAccount(iceSession, allowedAccount)) { foundAnAccount = true; logger.info("Found Account: " + allowedAccount); } } } } } } //require at least one account if (!foundAnAccount) { throw new LoginMethodException( "SAML Assertion must give at least one Account as part of the Assertion"); } //set expiration date DateTime startDate = assertion.getConditions().getNotBefore(); DateTime endDate = assertion.getConditions().getNotOnOrAfter(); if (startDate == null || endDate == null) { throw new LoginMethodException("Assertion must state an expiration date"); } // Clocks may not be synchronized. startDate = startDate.minusMinutes(2); endDate = endDate.plusMinutes(2); logger.info(startDate.toCalendar(null).getTime().toString()); logger.info(endDate.toCalendar(null).getTime().toString()); lr.loginStart = startDate.toCalendar(null).getTime(); lr.loginEnd = endDate.toCalendar(null).getTime(); }
From source file:com.scit.sling.test.MockValueMap.java
License:Open Source License
@SuppressWarnings("unchecked") private <T> T convertType(Object o, Class<T> type) { if (o == null) { return null; }//from w w w .j ava 2s . c o m if (o.getClass().isArray() && type.isArray()) { if (type.getComponentType().isAssignableFrom(o.getClass().getComponentType())) { return (T) o; } else { // we need to convert the elements in the array Object array = Array.newInstance(type.getComponentType(), Array.getLength(o)); for (int i = 0; i < Array.getLength(o); i++) { Array.set(array, i, convertType(Array.get(o, i), type.getComponentType())); } return (T) array; } } if (o.getClass().isAssignableFrom(type)) { return (T) o; } if (String.class.isAssignableFrom(type)) { // Format dates if (o instanceof Calendar) { return (T) formatDate((Calendar) o); } else if (o instanceof Date) { return (T) formatDate((Date) o); } else if (o instanceof DateTime) { return (T) formatDate((DateTime) o); } return (T) String.valueOf(o); } else if (o instanceof DateTime) { DateTime dt = (DateTime) o; if (Calendar.class.isAssignableFrom(type)) { return (T) dt.toCalendar(Locale.getDefault()); } else if (Date.class.isAssignableFrom(type)) { return (T) dt.toDate(); } else if (Number.class.isAssignableFrom(type)) { return convertType(dt.getMillis(), type); } } else if (o instanceof Number && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) (Byte) ((Number) o).byteValue(); } else if (Double.class.isAssignableFrom(type)) { return (T) (Double) ((Number) o).doubleValue(); } else if (Float.class.isAssignableFrom(type)) { return (T) (Float) ((Number) o).floatValue(); } else if (Integer.class.isAssignableFrom(type)) { return (T) (Integer) ((Number) o).intValue(); } else if (Long.class.isAssignableFrom(type)) { return (T) (Long) ((Number) o).longValue(); } else if (Short.class.isAssignableFrom(type)) { return (T) (Short) ((Number) o).shortValue(); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal(o.toString()); } } else if (o instanceof Number && type.isPrimitive()) { final Number num = (Number) o; if (type == byte.class) { return (T) new Byte(num.byteValue()); } else if (type == double.class) { return (T) new Double(num.doubleValue()); } else if (type == float.class) { return (T) new Float(num.floatValue()); } else if (type == int.class) { return (T) new Integer(num.intValue()); } else if (type == long.class) { return (T) new Long(num.longValue()); } else if (type == short.class) { return (T) new Short(num.shortValue()); } } else if (o instanceof String && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) new Byte((String) o); } else if (Double.class.isAssignableFrom(type)) { return (T) new Double((String) o); } else if (Float.class.isAssignableFrom(type)) { return (T) new Float((String) o); } else if (Integer.class.isAssignableFrom(type)) { return (T) new Integer((String) o); } else if (Long.class.isAssignableFrom(type)) { return (T) new Long((String) o); } else if (Short.class.isAssignableFrom(type)) { return (T) new Short((String) o); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal((String) o); } } throw new NotImplementedException( "Can't handle conversion from " + o.getClass().getName() + " to " + type.getName()); }
From source file:com.userweave.domain.util.xml.InvoiceCreator.java
License:Open Source License
public Receipient evaluateReceipient(Study study) { Receipient receipientRV;//from w ww . jav a 2 s .co m /* Receipient.GERMAN_ALL (default) * Diese Rechnung wrde an alle Personen und Firmen ausgeliefert werden, * die angeben innerhalb von Deutschland ansssig zu sein. */ receipientRV = Receipient.GERMAN_ALL; if (study.getOwner() != null && study.getOwner().getBusinessRole() != null && study.getOwner().getAddress() != null && study.getOwner().getAddress().getCountry() != null) { if (study.getOwner().getAddress().getCountry() != Country.GERMANY) { // 1.1.2010 00:00:00 DateTime is2010 = new DateTime(2010, 1, 1, 0, 0, 0, 0); System.out.println("2010:" + is2010.toCalendar(Locale.GERMAN)); // skip equal case if (is2010.isEqualNow()) { try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } /* Receipient.OTHER_PRIVATE * Diese Rechnung wrde an alle Privatpersonen gehen, die nicht in * Deutschland ansssig sind und ab dem 1.1.2010 auch an alle Unternehmen, * die innerhalb der EU sitzen. */ if (study.getOwner().getBusinessRole() == BusinessRole.Individual || (is2010.isBeforeNow() && study.getOwner().getBusinessRole() == BusinessRole.Company && EUProvider.isInEU(study.getOwner().getAddress().getCountry()))) { receipientRV = Receipient.OTHER_PRIVATE; } /* Receipient.OTHER_COMPANY * Diese Rechnung wrde an alle Unternehmen gehen, die auerhalb Deutschlands * sitzen (ab 1.1.2010 an alle Unternehmen auerhalb der EU) */ else if (study.getOwner().getBusinessRole() == BusinessRole.Company || (is2010.isBeforeNow() && study.getOwner().getBusinessRole() == BusinessRole.Company && !EUProvider.isInEU(study.getOwner().getAddress().getCountry()))) { receipientRV = Receipient.OTHER_COMPANY; } } } else { //FIXME: Question: should throw Exception??? } return receipientRV; }
From source file:edu.internet2.middleware.grouperClientExt.com.thoughtworks.xstream.converters.extended.ISO8601GregorianCalendarConverter.java
License:Open Source License
public Object fromString(String str) { for (int i = 0; i < formattersUTC.length; i++) { DateTimeFormatter formatter = formattersUTC[i]; try {//from w w w . ja v a 2s. c o m DateTime dt = formatter.parseDateTime(str); Calendar calendar = dt.toCalendar(Locale.getDefault()); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (IllegalArgumentException e) { // try with next formatter } } String timeZoneID = TimeZone.getDefault().getID(); for (int i = 0; i < formattersNoUTC.length; i++) { try { DateTimeFormatter formatter = formattersNoUTC[i].withZone(DateTimeZone.forID(timeZoneID)); DateTime dt = formatter.parseDateTime(str); Calendar calendar = dt.toCalendar(Locale.getDefault()); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (IllegalArgumentException e) { // try with next formatter } } throw new ConversionException("Cannot parse date " + str); }