PageRenderTime 21ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/utils/date/vTimeframe.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 78 lines | 33 code | 10 blank | 35 comment | 3 complexity | c1af4085456108a0e7a0767a5c8e35b5 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. *
  3. *
  4. */
  5. package mpv5.utils.date;
  6. import java.util.Date;
  7. /**
  8. *
  9. * This class implements a timeframe between two dates
  10. */
  11. public class vTimeframe {
  12. private Date start;
  13. private Date end;
  14. private long time;
  15. /**
  16. * Create a new timeframe
  17. * @param start
  18. * @param ende
  19. */
  20. public vTimeframe(Date start, Date ende) {
  21. this.start = start;
  22. this.end = ende;
  23. this.time = end.getTime() - start.getTime();
  24. }
  25. /**
  26. * Create a new timeframe
  27. * @param von
  28. * @param bis
  29. */
  30. public vTimeframe(vDate von, vDate bis){
  31. this.start = von.getDate();
  32. this.end = bis.getDate();
  33. this.time = end.getTime() - start.getTime();
  34. }
  35. /**
  36. * Checks whether the given date is within this timeframe
  37. * @param day
  38. * @return True if the date is within or at the timeframe`s start or end date
  39. */
  40. public boolean contains(Date day) {
  41. return this.getEnd().equals(day) || this.getStart().equals(day) || (day.after(this.getStart()) && day.before(this.getEnd()));
  42. }
  43. /**
  44. * The start
  45. * @return
  46. */
  47. public Date getStart() {
  48. return start;
  49. }
  50. /**
  51. * The end date
  52. * @return
  53. */
  54. public Date getEnd() {
  55. return end;
  56. }
  57. /**
  58. *
  59. * @return The difference of start and end in millis
  60. */
  61. public long getTime() {
  62. return time;
  63. }
  64. @Override
  65. public String toString(){
  66. return start + " - " + end;
  67. }
  68. }