1/*
2 * Copyright (C) 2018 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 android.os;
18
19import java.time.Clock;
20import java.time.Instant;
21import java.time.ZoneId;
22
23/** {@hide} */
24public abstract class SimpleClock extends Clock {
25    private final ZoneId zone;
26
27    public SimpleClock(ZoneId zone) {
28        this.zone = zone;
29    }
30
31    @Override
32    public ZoneId getZone() {
33        return zone;
34    }
35
36    @Override
37    public Clock withZone(ZoneId zone) {
38        return new SimpleClock(zone) {
39            @Override
40            public long millis() {
41                return SimpleClock.this.millis();
42            }
43        };
44    }
45
46    @Override
47    public abstract long millis();
48
49    @Override
50    public Instant instant() {
51        return Instant.ofEpochMilli(millis());
52    }
53}
54