PageRenderTime 112ms CodeModel.GetById 27ms app.highlight 2ms RepoModel.GetById 81ms 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
 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 */
17package mpv5.utils.date;
18
19import java.util.Date;
20import java.util.Random;
21
22/**
23 * Creates a random date within the given timeframe
24 *  
25 */
26public class RandomDate extends Date {
27
28    private static final long serialVersionUID = 1L;
29
30    public RandomDate(vTimeframe timeframe) {
31        if (timeframe != null) {
32            long start = timeframe.getStart().getTime();
33            long end = timeframe.getEnd().getTime();
34            Random r = new Random();
35            long randomTS = (long) (r.nextDouble() * (end - start)) + start;
36            this.setTime(randomTS);
37        }
38    }
39}