001package de.cuioss.test.generator.impl;
002
003import static de.cuioss.test.generator.Generators.integers;
004
005import java.time.ZonedDateTime;
006
007import de.cuioss.test.generator.Generators;
008import de.cuioss.test.generator.TypedGenerator;
009
010/**
011 * Provide any value for {@linkplain ZonedDateTime}
012 *
013 * @author Eugen Fischer
014 */
015public class ZonedDateTimeGenerator implements TypedGenerator<ZonedDateTime> {
016
017    private static final TypedGenerator<Integer> SOME_INT = integers(0, 10);
018
019    @Override
020    public ZonedDateTime next() {
021        return ZonedDateTime.ofInstant(Generators.dates().next().toInstant(), Generators.zoneIds().next());
022    }
023
024    @Override
025    public Class<ZonedDateTime> getType() {
026        return ZonedDateTime.class;
027    }
028
029    /**
030     * @return an arbitrary ZonedDateTime
031     */
032    public static ZonedDateTime any() {
033        return new ZonedDateTimeGenerator().next();
034    }
035
036    /**
037     * @return value of ZonedDateTime for now
038     */
039    public static ZonedDateTime now() {
040        return ZonedDateTime.now();
041    }
042
043    /**
044     * @return value of ZonedDateTime one hour ago
045     */
046    public static ZonedDateTime someMinutesAgo() {
047        return now().minusMinutes(SOME_INT.next());
048    }
049
050    /**
051     * @return value of ZonedDateTime one hour ago
052     */
053    public static ZonedDateTime someHoursAgo() {
054        return now().minusHours(SOME_INT.next());
055    }
056
057    /**
058     * @return value of ZonedDateTime one day ago
059     */
060    public static ZonedDateTime someDaysAgo() {
061        return now().minusDays(SOME_INT.next());
062    }
063
064    /**
065     * @return value of ZonedDateTime one week ago
066     */
067    public static ZonedDateTime someWeeksAgo() {
068        return now().minusWeeks(SOME_INT.next());
069    }
070
071    /**
072     * @return value of ZonedDateTime one month ago
073     */
074    public static ZonedDateTime someMonthsAgo() {
075        return now().minusMonths(SOME_INT.next());
076    }
077
078    /**
079     * @return value of ZonedDateTime one year ago
080     */
081    public static ZonedDateTime someYearsAgo() {
082        return now().minusYears(SOME_INT.next());
083    }
084
085    /**
086     * @return value of ZonedDateTime with date somewhere 10 years ago
087     */
088    public static ZonedDateTime lastTenYearsAgo() {
089        return now()
090                .minusYears(SOME_INT.next())
091                .minusMonths(SOME_INT.next())
092                .minusDays(SOME_INT.next());
093    }
094
095    /**
096     * @return value of ZonedDateTime with date somewhere lastMonth
097     */
098    public static ZonedDateTime lastMonthAgo() {
099        return now().minusMinutes(SOME_INT.next())
100                .minusHours(SOME_INT.next())
101                .minusDays(SOME_INT.next());
102    }
103}