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.

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

mercurial