Android Week Get getWeeksSinceEpochFromJulianDay(int julianDay, int firstDayOfWeek)

Here you can find the source of getWeeksSinceEpochFromJulianDay(int julianDay, int firstDayOfWeek)

Description

Returns the week since Time#EPOCH_JULIAN_DAY (Jan 1, 1970) adjusted for first day of week.

License

Apache License

Parameter

Parameter Description
julianDay The julian day to calculate the week number for
firstDayOfWeek Which week day is the first day of the week, see Time#SUNDAY

Return

Weeks since the epoch

Declaration

public static int getWeeksSinceEpochFromJulianDay(int julianDay,
        int firstDayOfWeek) 

Method Source Code

//package com.java2s;
/*//from   w  ww. j  a v a 2 s  . c  om
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.text.format.Time;

public class Main {
    /**
     * Returns the week since {@link Time#EPOCH_JULIAN_DAY} (Jan 1, 1970)
     * adjusted for first day of week.
     * <p/>
     * This takes a julian day and the week start day and calculates which
     * week since {@link Time#EPOCH_JULIAN_DAY} that day occurs in, starting
     * at 0. *Do not* use this to compute the ISO week number for the year.
     *
     * @param julianDay      The julian day to calculate the week number for
     * @param firstDayOfWeek Which week day is the first day of the week,
     *                       see {@link Time#SUNDAY}
     * @return Weeks since the epoch
     */
    public static int getWeeksSinceEpochFromJulianDay(int julianDay,
            int firstDayOfWeek) {
        int diff = Time.THURSDAY - firstDayOfWeek;
        if (diff < 0) {
            diff += 7;
        }
        int refDay = Time.EPOCH_JULIAN_DAY - diff;
        return (julianDay - refDay) / 7;
    }
}

Related

  1. getDateAWeekAgo(Date date)
  2. getDateInAWeek(Date date)
  3. getStartAndEndDatesForWeek(Calendar currentDate, Calendar startDate, Calendar endDate)
  4. getDaysOfWeekNames()
  5. getDaysOfWeekNames(Locale l, int len)
  6. getEnglishDayInWeek(Date date)