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;
	}
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...