Code example for Time

Methods: format, set, setJulianDay

0
    } 
 
    protected String getTitleForPosition(int pos) {
        final YearAndMonth ym = getYearAndMonthForPosition(pos);
 
        mTime.set(1, ym.month, ym.year);
        return mTime.format("%b %Y");
    } 
 
    public void selectJulianDay(int pos, int jd) {
        WeakReference<MonthFragment> fragRes = mPosToFragRef.get(pos);
        MonthFragment frag = fragRes == null ? null : fragRes.get();
 
        if(frag != null) {
            frag.selectJulianDay(jd);
        } 
    } 
 
    public int getPositionForJulianDay(int julianDay) {
        mTime.setJulianDay(mCenterJulianDay);
 
        Calendar center = Calendar.getInstance();
        center.set(mTime.year, mTime.month, 1);
 
        mTime.setJulianDay(julianDay);
 
        Calendar query = Calendar.getInstance();
        query.set(mTime.year, mTime.month, 1);
 
        int diff = getMonthsDifference(center, query);
        return getCenterPosition() + diff - 1;
    } 
 
    public int getSelectedJulianDay(int pos) {
        int jd = mCenterJulianDay;
 
        WeakReference<MonthFragment> fragRes = mPosToFragRef.get(pos);
        MonthFragment frag = fragRes.get();
 
        if(frag != null)
            jd = frag.getSelectedJulianDay();
 
        return jd;
    } 
 
    private YearAndMonth getYearAndMonthForPosition(int pos) {
        final int middle = getCenterPosition();
        mTime.setJulianDay(mCenterJulianDay);
 
        YearAndMonth ym = new YearAndMonth(mTime.year, mTime.month);
        if(pos != middle) {
            Calendar cal = Calendar.getInstance();
            cal.set(ym.year, ym.month, 1);