mobile/android/base/background/common/DateUtils.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.background.common;
michael@0 6
michael@0 7 import java.util.Calendar;
michael@0 8 import java.util.Formatter;
michael@0 9 import java.util.TimeZone;
michael@0 10
michael@0 11 public class DateUtils {
michael@0 12 private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
michael@0 13
michael@0 14 public static final class DateFormatter {
michael@0 15 private final Calendar calendar;
michael@0 16 private final Formatter formatter;
michael@0 17 private final StringBuilder builder;
michael@0 18
michael@0 19 public DateFormatter() {
michael@0 20 this.calendar = Calendar.getInstance(UTC);
michael@0 21 this.builder = new StringBuilder(); // So we can reset it.
michael@0 22 this.formatter = new Formatter(this.builder, null);
michael@0 23 }
michael@0 24
michael@0 25 public String getDateString(long time) {
michael@0 26 calendar.setTimeInMillis(time);
michael@0 27 builder.setLength(0);
michael@0 28 return formatter.format("%04d-%02d-%02d",
michael@0 29 calendar.get(Calendar.YEAR),
michael@0 30 calendar.get(Calendar.MONTH) + 1, // 0-indexed.
michael@0 31 calendar.get(Calendar.DAY_OF_MONTH))
michael@0 32 .toString();
michael@0 33 }
michael@0 34
michael@0 35 public String getDateStringForDay(long day) {
michael@0 36 return getDateString(GlobalConstants.MILLISECONDS_PER_DAY * day);
michael@0 37 }
michael@0 38 }
michael@0 39
michael@0 40 public static int getDay(final long time) {
michael@0 41 return (int) Math.floor(time / GlobalConstants.MILLISECONDS_PER_DAY);
michael@0 42 }
michael@0 43 }

mercurial