You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DateUtil.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.v7.client.ui.calendar.schedule;
  17. import java.util.Date;
  18. import com.google.gwt.i18n.client.DateTimeFormat;
  19. import com.vaadin.v7.shared.ui.calendar.DateConstants;
  20. /**
  21. * Utility class for {@link Date} operations.
  22. *
  23. * @since 7.1
  24. * @author Vaadin Ltd.
  25. */
  26. public class DateUtil {
  27. /**
  28. * Checks if dates are same day without checking datetimes.
  29. *
  30. * @param date1
  31. * @param date2
  32. * @return
  33. */
  34. @SuppressWarnings("deprecation")
  35. public static boolean compareDate(Date date1, Date date2) {
  36. if (date1.getDate() == date2.getDate()
  37. && date1.getYear() == date2.getYear()
  38. && date1.getMonth() == date2.getMonth()) {
  39. return true;
  40. }
  41. return false;
  42. }
  43. /**
  44. * @param date
  45. * the date to format
  46. *
  47. * @return given Date as String, for communicating to server-side
  48. */
  49. public static String formatClientSideDate(Date date) {
  50. DateTimeFormat dateformatDate = DateTimeFormat
  51. .getFormat(DateConstants.CLIENT_DATE_FORMAT);
  52. return dateformatDate.format(date);
  53. }
  54. /**
  55. * @param date
  56. * the date to format
  57. * @return given Date as String, for communicating to server-side
  58. */
  59. public static String formatClientSideTime(Date date) {
  60. DateTimeFormat dateformatDate = DateTimeFormat
  61. .getFormat(DateConstants.CLIENT_TIME_FORMAT);
  62. return dateformatDate.format(date);
  63. }
  64. }