Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TimeUnits.java
Go to the documentation of this file.
1/*
2 * Sleuth Kit Data Model
3 *
4 * Copyright 2018 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.timeline.zooming;
20
21import java.time.temporal.ChronoUnit;
22import org.apache.commons.lang3.StringUtils;
23import org.joda.time.DateTime;
24import org.joda.time.DateTimeFieldType;
25import org.joda.time.Days;
26import org.joda.time.Hours;
27import org.joda.time.Minutes;
28import org.joda.time.Months;
29import org.joda.time.Period;
30import org.joda.time.ReadablePeriod;
31import org.joda.time.Seconds;
32import org.joda.time.Years;
33import org.joda.time.format.DateTimeFormat;
34import org.joda.time.format.DateTimeFormatter;
35import org.joda.time.format.ISODateTimeFormat;
36
40public enum TimeUnits {
41
42 FOREVER(null, null, ChronoUnit.FOREVER, null),
43 YEARS(DateTimeFieldType.year(), Years.ONE, ChronoUnit.YEARS, ISODateTimeFormat.year()),
44 MONTHS(DateTimeFieldType.monthOfYear(), Months.ONE, ChronoUnit.MONTHS, DateTimeFormat.forPattern("YYYY'-'MMMM")),
45 DAYS(DateTimeFieldType.dayOfMonth(), Days.ONE, ChronoUnit.DAYS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd")),
46 HOURS(DateTimeFieldType.hourOfDay(), Hours.ONE, ChronoUnit.HOURS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH")),
47 MINUTES(DateTimeFieldType.minuteOfHour(), Minutes.ONE, ChronoUnit.MINUTES, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm")),
48 SECONDS(DateTimeFieldType.secondOfMinute(), Seconds.ONE, ChronoUnit.SECONDS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm':'ss"));
49
50 private final DateTimeFieldType fieldType;
51 private final Period period;
52 private final ChronoUnit chronoUnit;
53 private final DateTimeFormatter tickFormatter;
54
55 public DateTimeFormatter getTickFormatter() {
56 return tickFormatter;
57 }
58
59 private TimeUnits(DateTimeFieldType fieldType, ReadablePeriod period, ChronoUnit chronoUnit, DateTimeFormatter tickFormatter) {
60 this.fieldType = fieldType;
61 if (period != null) {
62 this.period = period.toPeriod();
63 } else {
64 this.period = null;
65 }
66 this.chronoUnit = chronoUnit;
67 this.tickFormatter = tickFormatter;
68 }
69
70 public DateTime.Property propertyOf(DateTime dateTime) {
71 return dateTime.property(fieldType);
72 }
73
74 public Period toUnitPeriod() {
75 return period;
76 }
77
78 public ChronoUnit toChronoUnit() {
79 return chronoUnit;
80 }
81
82 public String getDisplayName() {
83 return StringUtils.capitalize(toString().toLowerCase());
84 }
85}
DateTime.Property propertyOf(DateTime dateTime)
TimeUnits(DateTimeFieldType fieldType, ReadablePeriod period, ChronoUnit chronoUnit, DateTimeFormatter tickFormatter)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.