19package org.sleuthkit.autopsy.datasourceprocessors.xry;
21import java.time.Instant;
22import java.util.Locale;
23import java.time.LocalDateTime;
24import java.time.OffsetDateTime;
25import java.time.ZoneId;
26import java.time.ZonedDateTime;
27import java.time.format.DateTimeFormatter;
28import java.time.temporal.TemporalAccessor;
29import java.time.temporal.TemporalQueries;
30import org.sleuthkit.datamodel.CommunicationsUtils;
31import org.sleuthkit.datamodel.InvalidAccountIDException;
40 private static final DateTimeFormatter DATE_TIME_PARSER
41 = DateTimeFormatter.ofPattern(
"[(XXX) ][O ][(O) ]a h:m:s M/d/y");
43 private static final String DEVICE_LOCALE =
"(device)";
44 private static final String NETWORK_LOCALE =
"(network)";
46 public static boolean isPhoneValid(String phoneNumber) {
48 CommunicationsUtils.normalizePhoneNum(phoneNumber);
50 }
catch (InvalidAccountIDException ex) {
55 public static boolean isEmailValid(String email) {
57 CommunicationsUtils.normalizeEmailAddress(email);
59 }
catch (InvalidAccountIDException ex) {
70 public static long calculateSecondsSinceEpoch(String dateTime) {
71 String dateTimeWithoutLocale = removeDateTimeLocale(dateTime).trim();
88 String reversedDateTime = reverseOrderOfDateTimeComponents(dateTimeWithoutLocale);
96 String reversedDateTimeWithGMT = reversedDateTime.replace(
"UTC",
"GMT");
97 TemporalAccessor result = DATE_TIME_PARSER.parseBest(reversedDateTimeWithGMT,
100 OffsetDateTime::from);
102 if (result.query(TemporalQueries.zoneId()) ==
null) {
104 return ZonedDateTime.of(LocalDateTime.from(result),
105 ZoneId.of(
"GMT")).toEpochSecond();
107 return Instant.from(result).getEpochSecond();
119 private static String reverseOrderOfDateTimeComponents(String dateTime) {
120 StringBuilder reversedDateTime =
new StringBuilder(dateTime.length());
121 String[] dateTimeComponents = dateTime.split(
" ");
122 for (String component : dateTimeComponents) {
123 reversedDateTime.insert(0,
" ").insert(0, component);
125 return reversedDateTime.toString().trim();
136 private static String removeDateTimeLocale(String dateTime) {
137 String result = dateTime;
138 int deviceIndex = result.toLowerCase(Locale.ROOT).indexOf(DEVICE_LOCALE);
139 if (deviceIndex != -1) {
140 result = result.substring(0, deviceIndex);
142 int networkIndex = result.toLowerCase(Locale.ROOT).indexOf(NETWORK_LOCALE);
143 if (networkIndex != -1) {
144 result = result.substring(0, networkIndex);