Java Timestamp IsTechStatisticWorkTime(Timestamp timestamp)

Here you can find the source of IsTechStatisticWorkTime(Timestamp timestamp)

Description

Is Tech Statistic Work Time

License

Open Source License

Parameter

Parameter Description
timestamp a parameter

Declaration

public static boolean IsTechStatisticWorkTime(Timestamp timestamp) 

Method Source Code

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

import java.sql.Timestamp;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static boolean IsTechStatisticWorkTime(Timestamp timestamp) {
        try {// ww  w .  j a  v  a  2  s . c  o  m
            int weekDay = getDayOfWeek(timestamp);

            if (weekDay >= 1 && weekDay <= 5) {
                if ((timestamp.getHours() >= 8 && timestamp.getHours() < 22)) {
                    return true;
                }
            } else {
                if (((timestamp.getHours() >= 10))
                        && timestamp.getHours() < 19) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }

    public static int getDayOfWeek(Timestamp timestamp) {
        Calendar cal = Calendar.getInstance();
        Date date = new Date(timestamp.getTime());
        cal.setTime(date);
        int dayForWeek = 0;
        dayForWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (dayForWeek == 1) {
            dayForWeek = 7;
        } else {
            dayForWeek = dayForWeek - 1;
        }
        return dayForWeek;
    }
}

Related

  1. isInPast(Timestamp timeStamp)
  2. isLongDate(Timestamp date)
  3. isLongTerm(Timestamp oldTime, Timestamp newTime)
  4. isSameDay(Timestamp one, Timestamp two)
  5. isSameMonth(Timestamp t1, Timestamp t2)
  6. isTimeStamp(Class o)
  7. isTimestamp(String aS_DateTime, String aS_Format)
  8. isTimestamp(String str)
  9. isValid(Timestamp validFrom, Timestamp validTo, Timestamp testDate)