Android Time to Hour Convert hoursToEndOfMonth(Time t)

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

Description

Return number of whole hours to the end of month of a given time.

License

Apache License

Parameter

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

Declaration

public static final int hoursToEndOfMonth(Time t) 

Method Source Code

//package com.java2s;
/*/*from w ww. j av  a  2  s  .c o  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 hours to the end of month of a given time.
     * 
     * @param the time (can contains hours, minutes, seconds, millis).
     */
    public static final int hoursToEndOfMonth(Time t) {
        // [1..31] (actually 28, 29, 30, 31).
        final int hoursInThisMonth = 24 * t
                .getActualMaximum(Time.MONTH_DAY);
        final int hoursPassedInThisMonth = ((t.monthDay - 1) * 24) + t.hour;
        // NOTE: clipping to zero just in case. Should not happen.
        return Math.max(0, hoursInThisMonth - hoursPassedInThisMonth);
    }
}