blob: 41889aa5b2248322d3a00405fadcf6d4d6f3f7d4 [file] [log] [blame]
Danning Chena1bf86d2020-01-14 16:09:24 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.people.data;
18
19import java.time.LocalDateTime;
20import java.time.ZoneId;
21import java.time.format.DateTimeFormatter;
22
23final class TestUtils {
24
25 /**
26 * Gets the epoch time in millis for the specified time string.
27 * @param timeString e.g. "01-02 15:20"
28 * @return epoch time in millis
29 */
30 static long timestamp(String timeString) {
31 String str = String.format("2020-%s", timeString);
32 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
33 return toEpochMilli(LocalDateTime.parse(str, formatter));
34 }
35
36 private static long toEpochMilli(LocalDateTime localDateTime) {
37 return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
38 }
39
40 private TestUtils() {
41 }
42}