Advertisement
Guest User

Untitled

a guest
Jan 16th, 2013
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public static String format(Date date, Locale locale, FORMAT_TYPE type) {
  2. log.debug("Formatting date: " + date + " with locale " + locale);
  3.  
  4. DateFormat dateFormat = null;
  5.  
  6. if (type == FORMAT_TYPE.TIMESTAMP) {
  7. String dateTimeFormat = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GLOBAL_PROPERTY_DATEANDTIME_DISPLAY_FORMAT, null);
  8. if (StringUtils.isEmpty(dateTimeFormat))
  9. dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
  10. else
  11. dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(dateTimeFormat), locale);
  12. }
  13. else if (type == FORMAT_TYPE.TIME) {
  14. String timeFormat = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GLOBAL_PROPERTY_TIME_DISPLAY_FORMAT, null);
  15. if (StringUtils.isEmpty(timeFormat))
  16. dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
  17. else
  18. dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(timeFormat), locale);
  19. }
  20. else if (type == FORMAT_TYPE.DATE) {
  21. String formatValue = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GLOBAL_POPERTY_DATE_DISPLAY_FORMAT, null);
  22. if (StringUtils.isEmpty(formatValue))
  23. dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
  24. else
  25. dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(formatValue), locale);
  26. }
  27. return date == null ? "" : dateFormat.format(date);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement