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