PageRenderTime 59ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/utils/date/RandomDate.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 39 lines | 15 code | 4 blank | 20 comment | 2 complexity | 135b3ab3fc1d2f37b40461f8739961f4 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. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.utils.date;
  18. import java.util.Date;
  19. import java.util.Random;
  20. /**
  21. * Creates a random date within the given timeframe
  22. *
  23. */
  24. public class RandomDate extends Date {
  25. private static final long serialVersionUID = 1L;
  26. public RandomDate(vTimeframe timeframe) {
  27. if (timeframe != null) {
  28. long start = timeframe.getStart().getTime();
  29. long end = timeframe.getEnd().getTime();
  30. Random r = new Random();
  31. long randomTS = (long) (r.nextDouble() * (end - start)) + start;
  32. this.setTime(randomTS);
  33. }
  34. }
  35. }