Compute ouput text for event dates

public String getEventDate(DominoDocument doc) {
		String date = "/tba";
		Locale locale = Locale.ENGLISH;
		SimpleDateFormat f = new SimpleDateFormat("MMMM dd, yyyy", locale);
		SimpleDateFormat sf = new SimpleDateFormat("MMMM dd", locale);
		SimpleDateFormat day = new SimpleDateFormat("dd", locale);
		SimpleDateFormat year = new SimpleDateFormat("yyyy", locale);
		double oneDay = 86400;
		try {
			if (doc.hasItem("eventDate") && doc.hasItem("eventDateTo")) {
				DateTime from = doc.getItemValueDateTime("eventDate");
				DateTime to = doc.getItemValueDateTime("eventDateTo");

				// one day
				if (from.toJavaDate().getTime() == to.toJavaDate().getTime()) {
					date = f.format(from.toJavaDate());
				}

				// two days
				if (to.timeDifference(from) == oneDay) {
					date = sf.format(from.toJavaDate()) + " + " + day.format(to.toJavaDate()) + ", "
							+ year.format(from.toJavaDate());
				}

				// more days
				if (to.timeDifference(from) > oneDay) {
					date = sf.format(from.toJavaDate()) + " - " + day.format(to.toJavaDate()) + ", "
							+ year.format(from.toJavaDate());
				}
			}
		} catch (NotesException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}





This snippet computes a simple string for events depending on the start and end date. Change the locale and the format to your needs.

Java
Oliver Busse
March 2, 2016 5:37 PM
Rating
2

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...