Android Time to Week hoursToEndOfWeek(Time t)

Here you can find the source of hoursToEndOfWeek(Time t)

Description

Return number of whole hoursto the end of the week of a given time.

License

Apache License

Parameter

Parameter Description
the time (can contains hours, minutes, seconds, millis).

Declaration

public static final int hoursToEndOfWeek(Time t) 

Method Source Code

//package com.java2s;
/*/*from   ww  w  .j  ava  2  s. co m*/
 * Copyright (C) 2011 The original author or authors.
 * 
 * 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 {
    /**
     * Return number of whole hoursto the end of the week of a given time.
     * 
     * @param the time (can contains hours, minutes, seconds, millis).
     */
    public static final int hoursToEndOfWeek(Time t) {
        // Normalize to have a valid day of week
        t.normalize(false);
        final int hoursPassedInWeek = (t.weekDay * 24) + t.hour;
        // NOTE: clipping at zero just in case. Should not happen.
        return Math.max(0, (7 * 24) - hoursPassedInWeek);
    }
}