1d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie/**
2d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * Copyright (C) 2014 The Android Open Source Project
3d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie *
4d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * use this file except in compliance with the License. You may obtain a copy
6d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * of the License at
7d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie *
8d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * http://www.apache.org/licenses/LICENSE-2.0
9d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie *
10d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * Unless required by applicable law or agreed to in writing, software
11d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * License for the specific language governing permissions and limitations
14d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * under the License.
15d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie */
16d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffiepackage com.android.server.usage;
17d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
18d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie/**
19d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * A handy calendar object that knows nothing of Locale's or TimeZones. This simplifies
20d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * interval book-keeping. It is *NOT* meant to be used as a user-facing calendar, as it has
21d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie * no concept of Locale or TimeZone.
22d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie */
23d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffiepublic class UnixCalendar {
24d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public static final long DAY_IN_MILLIS = 24 * 60 * 60 * 1000;
25d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public static final long WEEK_IN_MILLIS = 7 * DAY_IN_MILLIS;
26d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public static final long MONTH_IN_MILLIS = 30 * DAY_IN_MILLIS;
27d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public static final long YEAR_IN_MILLIS = 365 * DAY_IN_MILLIS;
28d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    private long mTime;
29d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
30d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public UnixCalendar(long time) {
31d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie        mTime = time;
32d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    }
33d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
34d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public void addDays(int val) {
35d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie        mTime += val * DAY_IN_MILLIS;
36d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    }
37d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
38d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public void addWeeks(int val) {
39d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie        mTime += val * WEEK_IN_MILLIS;
40d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    }
41d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
42d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public void addMonths(int val) {
43d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie        mTime += val * MONTH_IN_MILLIS;
44d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    }
45d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
46d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public void addYears(int val) {
47d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie        mTime += val * YEAR_IN_MILLIS;
48d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    }
49d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
50d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public void setTimeInMillis(long time) {
51d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie        mTime = time;
52d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    }
53d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie
54d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    public long getTimeInMillis() {
55d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie        return mTime;
56d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    }
57d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie}
58d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie