Java Timestamp Field getRealCalendar(Timestamp time)

Here you can find the source of getRealCalendar(Timestamp time)

Description

get Real Calendar

License

Open Source License

Declaration

protected static Calendar getRealCalendar(Timestamp time) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Timestamp;
import java.util.Calendar;

public class Main {
    protected static Calendar getRealCalendar(Timestamp time) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(time.getTime());

        if (c.get(Calendar.DAY_OF_WEEK) == 6 && c.get(Calendar.HOUR_OF_DAY) >= 19) {
            c.setTimeInMillis(c.getTimeInMillis() + 86400000 * 3);
            clearTime(c);// w ww .jav  a2 s  .  c  o m
            return c;
        }

        if (c.get(Calendar.DAY_OF_WEEK) == 7) {
            c.setTimeInMillis(c.getTimeInMillis() + 86400000 * 2);
            clearTime(c);
            return c;
        }

        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            c.setTimeInMillis(c.getTimeInMillis() + 86400000);
            clearTime(c);
            return c;
        }

        if (c.get(Calendar.HOUR_OF_DAY) >= 10 && c.get(Calendar.HOUR_OF_DAY) < 19)
            return c;

        if (c.get(Calendar.HOUR_OF_DAY) >= 19)
            c.setTimeInMillis(c.getTimeInMillis() + 86400000);

        clearTime(c);
        return c;
    }

    protected static void clearTime(Calendar c) {
        c.set(Calendar.HOUR_OF_DAY, 10);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
    }
}

Related

  1. getPerformanceTime(Timestamp startTime)
  2. getPeriodExpiration(Timestamp tsStartDate, int iPeriodType, int iPeriodDuration)
  3. getPresentTimeStamp()
  4. getRandomTimeBetweenTwoDates(Timestamp beginDate, Map context)
  5. getRandTimestamp(Random r)
  6. getResultRowValueAsTimestamp(String valueName, Map resultRow)
  7. getSafeLong(final Timestamp d, final long i)
  8. getSeconds(Timestamp timeStamp)
  9. getServerToUserDateString(TimeZone timeZone, int dateFormat, java.sql.Timestamp date)