Autopsy  4.20.0
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  */
19 package org.sleuthkit.autopsy.timeline.zooming;
20 
21 import java.time.temporal.ChronoUnit;
22 import org.apache.commons.lang3.StringUtils;
23 import org.joda.time.DateTime;
24 import org.joda.time.DateTimeFieldType;
25 import org.joda.time.Days;
26 import org.joda.time.Hours;
27 import org.joda.time.Minutes;
28 import org.joda.time.Months;
29 import org.joda.time.Period;
30 import org.joda.time.ReadablePeriod;
31 import org.joda.time.Seconds;
32 import org.joda.time.Years;
33 import org.joda.time.format.DateTimeFormat;
34 import org.joda.time.format.DateTimeFormatter;
35 import org.joda.time.format.ISODateTimeFormat;
36 
40 public 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 }
TimeUnits(DateTimeFieldType fieldType, ReadablePeriod period, ChronoUnit chronoUnit, DateTimeFormatter tickFormatter)
Definition: TimeUnits.java:59
DateTime.Property propertyOf(DateTime dateTime)
Definition: TimeUnits.java:70

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.