下面列出了java.sql.Timestamp#after ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Used to request the remaining capacity available for dateFrom in a TechDataCalenda,
* If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is zero.
*
* @param techDataCalendar The TechDataCalendar cover
* @param dateFrom the date
* @return long capacityRemaining
*/
public static long capacityRemainingBackward(GenericValue techDataCalendar, Timestamp dateFrom) {
GenericValue techDataCalendarWeek = null;
// TODO read TechDataCalendarExcWeek to manage exception week (maybe it's needed to refactor the entity definition
try {
techDataCalendarWeek = techDataCalendar.getRelatedOne("TechDataCalendarWeek", true);
} catch (GenericEntityException e) {
Debug.logError("Pb reading Calendar Week associated with calendar"+e.getMessage(), module);
return 0;
}
// TODO read TechDataCalendarExcDay to manage execption day
Calendar cDateTrav = Calendar.getInstance();
cDateTrav.setTime(dateFrom);
Map<String, Object> position = dayEndCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK));
int moveDay = (Integer) position.get("moveDay");
if (moveDay != 0) return 0;
Time startTime = (Time) position.get("startTime");
Double capacity = (Double) position.get("capacity");
Timestamp startAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateFrom).getTime() + startTime.getTime() + cDateTrav.get(Calendar.ZONE_OFFSET) + cDateTrav.get(Calendar.DST_OFFSET));
if (dateFrom.before(startAvailablePeriod)) return 0;
Timestamp endAvailablePeriod = new Timestamp(startAvailablePeriod.getTime()+capacity.longValue());
if (dateFrom.after(endAvailablePeriod)) return 0;
return dateFrom.getTime() - startAvailablePeriod.getTime();
}
public void formatDate(Messageall messageall, Timestamp ttime) {
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
SimpleDateFormat sdf2 = new SimpleDateFormat("yy-MM-dd");
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
String nowyear = year + "-01-01 00:00:00";
Timestamp yeardate = Timestamp.valueOf(nowyear);
if (ttime.after(yeardate)) {
messageall.setTime(sdf.format(ttime));
} else {
messageall.setTime(sdf2.format(ttime));
}
}
public static boolean isDateAfterNow(Timestamp date) {
Timestamp now = UtilDateTime.nowTimestamp();
if (date != null) {
return date.after(now);
}
return false;
}
/**
* Check the consistency of a ResultSet column that returns
* CURRENT TIMESTAMP or a value set from CURRENT TIMESTAMP.
*
* @param start Time the statement settng the value was executed
* @param end Time after first rs.next() or update statement was executed
* @param rs ResultSet holding the column, positioned on a row
* @param column Column with the timestamp.
* @return Returns the Timestamp object obtained from the column.
* @throws SQLException
*/
private Timestamp checkCurrentTimestampValue(long start, long end,
ResultSet rs, int column) throws SQLException
{
Timestamp tsv = checkTimestampValue(rs, column);
// The time returned should be between the value
// of start and end (inclusive of both)
Timestamp st = new Timestamp(start);
Timestamp et = new Timestamp(end);
if (st.after(et)) {
// Gone back in time!
// Well test was running around midnight and the
// time for the start time is equal to or before 23:59:59
// and end time is equal to or after 00:00:00
assertTrue("CURRENT TIME outside of range when test crossing midnight",
(tsv.equals(st) || tsv.after(st))
|| (tsv.equals(et) || tsv.before(et)));
}
else
{
// End time is after or equal to start time, expected case.
// The returned time must not be before the
// start time or after the end time.
assertFalse("CURRENT TIME before start of statement", tsv.before(st));
assertFalse("CURRENT TIME after end of statement", tsv.after(et));
}
return tsv;
}
protected Timestamp getNextRunEndTime() {
long syncSplit = this.isOfflineSync ? offlineSyncSplitMillis : syncSplitMillis;
Timestamp nextRunEndTime = new Timestamp(this.currentRunStartTime.getTime() + syncSplit);
if (nextRunEndTime.after(this.syncEndStamp)) {
nextRunEndTime = this.syncEndStamp;
}
return nextRunEndTime;
}
private Timestamp getLatestTimestamp(Timestamp date1, Timestamp date2) {
if (date1 != null && date2 == null)
return date1;
if (date1 == null && date2 != null)
return date2;
if (date1.after(date2))
return date1;
return date2;
}
public boolean asOfDateMatchesRange(Timestamp asOfDate, Timestamp from, Timestamp to)
{
if (asOfDate.equals(this.getInfinityDate()))
{
return to.equals(this.getInfinityDate());
}
else
{
if (to.after(asOfDate) || (this.isToIsInclusive() && to.equals(asOfDate)))
{
return from.before(asOfDate) || (!this.isToIsInclusive() && from.equals(asOfDate));
}
}
return false;
}
public static boolean isMilestoningValid(Object obj, AsOfAttribute[] asOfAttributes)
{
for (AsOfAttribute asOfAttribute : asOfAttributes)
{
Timestamp from = asOfAttribute.getFromAttribute().valueOf(obj);
Timestamp to = asOfAttribute.getToAttribute().valueOf(obj);
if (from.equals(to) || from.after(to))
{
return false;
}
}
return true;
}
public static boolean isSellable(GenericValue product, Timestamp atTime) {
if (product != null) {
Timestamp introDate = product.getTimestamp("introductionDate");
Timestamp discDate = product.getTimestamp("salesDiscontinuationDate");
if (introDate == null || introDate.before(atTime)) {
if (discDate == null || discDate.after(atTime)) {
return true;
}
}
}
return false;
}
@Override
public int compare(Row first, Row second) {
Timestamp ts1 = first.getAs(field.name());
Timestamp ts2 = second.getAs(field.name());
if (ts1.before(ts2)) {
return -1;
} else if (ts1.after(ts2)) {
return 1;
} else {
return 0;
}
}
@Test(expectedExceptions = NullPointerException.class)
public void test22() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
ts1.after(null);
}
/**
* Compares two Timestamps with the expected result.
*
* @param ts1 the first Timestamp
* @param ts2 the second Timestamp
* @param expect the expected relation between ts1 and ts2; 0 if
* ts1 equals to ts2, or 1 if ts1 is after ts2, or -1 if ts1 is
* before ts2.
*/
private void compareTimestamps(Timestamp ts1, Timestamp ts2, int expected) {
boolean expectedResult = expected > 0;
boolean result = ts1.after(ts2);
if (result != expectedResult) {
errln("ts1.after(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
expectedResult = expected < 0;
result = ts1.before(ts2);
if (result != expectedResult) {
errln("ts1.before(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
expectedResult = expected == 0;
result = ts1.equals(ts2);
if (result != expectedResult) {
errln("ts1.equals(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
int x = ts1.compareTo(ts2);
int y = (x > 0) ? 1 : (x < 0) ? -1 : 0;
if (y != expected) {
errln("ts1.compareTo(ts2) returned " + x + ", expected "
+ relation(expected, "") + "0"
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
long t1 = ts1.getTime();
long t2 = ts2.getTime();
int z = (t1 > t2) ? 1 : (t1 < t2) ? -1 : 0;
if (z == 0) {
int n1 = ts1.getNanos();
int n2 = ts2.getNanos();
z = (n1 > n2) ? 1 : (n1 < n2) ? -1 : 0;
}
if (z != expected) {
errln("ts1.getTime() " + relation(z, "==") + " ts2.getTime(), expected "
+ relation(expected, "==")
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
}
@Test(expectedExceptions = NullPointerException.class)
public void test22() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
ts1.after(null);
}
public boolean isExtracted(AddDateAware object) throws IllegalArgumentException
{
ObjectUtils.assertInstance(AddDateAware.class, object);
Timestamp addDate = ((AddDateAware) object).getAddDate();
return (addDate == null) ? false : !addDate.after(date);
}
/**
* Compares two Timestamps with the expected result.
*
* @param ts1 the first Timestamp
* @param ts2 the second Timestamp
* @param expect the expected relation between ts1 and ts2; 0 if
* ts1 equals to ts2, or 1 if ts1 is after ts2, or -1 if ts1 is
* before ts2.
*/
private void compareTimestamps(Timestamp ts1, Timestamp ts2, int expected) {
boolean expectedResult = expected > 0;
boolean result = ts1.after(ts2);
if (result != expectedResult) {
errln("ts1.after(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
expectedResult = expected < 0;
result = ts1.before(ts2);
if (result != expectedResult) {
errln("ts1.before(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
expectedResult = expected == 0;
result = ts1.equals(ts2);
if (result != expectedResult) {
errln("ts1.equals(ts2) returned " + result
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
int x = ts1.compareTo(ts2);
int y = (x > 0) ? 1 : (x < 0) ? -1 : 0;
if (y != expected) {
errln("ts1.compareTo(ts2) returned " + x + ", expected "
+ relation(expected, "") + "0"
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
long t1 = ts1.getTime();
long t2 = ts2.getTime();
int z = (t1 > t2) ? 1 : (t1 < t2) ? -1 : 0;
if (z == 0) {
int n1 = ts1.getNanos();
int n2 = ts2.getNanos();
z = (n1 > n2) ? 1 : (n1 < n2) ? -1 : 0;
}
if (z != expected) {
errln("ts1.getTime() " + relation(z, "==") + " ts2.getTime(), expected "
+ relation(expected, "==")
+ ". (ts1=" + ts1 + ", ts2=" + ts2 + ")");
}
}
@Test(expectedExceptions = NullPointerException.class)
public void test22() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
ts1.after(null);
}
public String roll(List<Utweets> tweetsList, int uid) {
JSONArray js = new JSONArray();
for (Utweets utweets : tweetsList) {
if (utweets.getTzhuan() > 0) {
Forwards forward = forwardsDao.getForward(utweets.getTid(), utweets.getTtime());
int id = forward.getStid();
Utweets utweet = tweetsDao.getTweetsByTid(id);
utweets.setUtweets(utweet);
}
int tid = utweets.getTid();
boolean zhuaned = forwardsDao.selForward(uid, tid);
if (zhuaned == true)
utweets.setZhuaned(1);
else
utweets.setZhuaned(0);
boolean zaned = likesDao.selLike(uid, tid);
if (zaned == true)
utweets.setZaned(1);
else
utweets.setZaned(0);
Timestamp ttime = utweets.getTtime();
SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
SimpleDateFormat sdf3 = new SimpleDateFormat("HH:mm");
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
String nowyear = year + "-01-01 00:00:00";
Timestamp yeardate = Timestamp.valueOf(nowyear);
String nowday = year + "-" + month + "-" + day + " 00:00:00";
Timestamp date = Timestamp.valueOf(nowday);
// 此处转换为毫秒数
long millionSeconds = ttime.getTime();// 毫秒
long nowSeconds = System.currentTimeMillis();
long chazhi = nowSeconds - millionSeconds;
if (chazhi < 60000) {
utweets.setTime("现在");
} else if (chazhi < 3600000) {
long n = chazhi / 60000;
utweets.setTime(n + "分钟");
} else if (ttime.after(date)) {
utweets.setTime(sdf3.format(ttime));
} else if (ttime.after(yeardate)) {
utweets.setTime(sdf.format(ttime));
} else {
utweets.setTime(sdf2.format(ttime));
}
js.add(getJsonObj(utweets.getTid(), utweets.getUid(), utweets.getTcontent(), utweets.getTpic(),
utweets.getTvideo(), utweets.getTreply(), utweets.getTforward(), utweets.getTlike(),
utweets.getUname(), utweets.getUpwd(), utweets.getUrealname(), utweets.getUaite(),
utweets.getUonline(), utweets.getUabout(), utweets.getUlogo(), utweets.getUbg(), utweets.getUfans(),
utweets.getUtweet(), utweets.getUfollow(), utweets.getUcolor(), utweets.getTime(),
utweets.getUtweets(), utweets.getTzhuan(), utweets.getZaned(), utweets.getZhuaned()));
}
return js.toString();
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;charset=UTF-8");
String page = req.getParameter("page");
String tid = req.getParameter("tid");
List<Replyall> replys = replysDao.getAllReply(Integer.parseInt(tid), Integer.parseInt(page));
if (replys == null) {
return;
}
JSONArray js = new JSONArray();
for (Replyall reply : replys) {
Timestamp rtime = reply.getRtime();
SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
SimpleDateFormat sdf3 = new SimpleDateFormat("HH:mm");
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
String nowyear = year + "-01-01 00:00:00";
Timestamp yeardate = Timestamp.valueOf(nowyear);
String nowday = year + "-" + month + "-" + day + " 00:00:00";
Timestamp date = Timestamp.valueOf(nowday);
// 此处转换为毫秒数
long millionSeconds = rtime.getTime();// 毫秒
long nowSeconds = System.currentTimeMillis();
long chazhi = nowSeconds - millionSeconds;
if (chazhi < 60000) {
reply.setTime("现在");
} else if (chazhi < 3600000) {
long n = chazhi / 60000;
reply.setTime(n + "分钟");
} else if (rtime.after(date)) {
reply.setTime(sdf3.format(rtime));
} else if (rtime.after(yeardate)) {
reply.setTime(sdf.format(rtime));
} else {
reply.setTime(sdf2.format(rtime));
}
js.add(getJsonObj(reply.getRid(), reply.getUid(), reply.getTid(), reply.getRcontent(), reply.getTime(),
reply.getUname(), reply.getUrealname(), reply.getUaite(), reply.getUlogo()));
}
resp.getWriter().print(js.toString());
}
@Test(expectedExceptions = NullPointerException.class)
public void test22() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
ts1.after(null);
}
/**
*
* Used to check if there is not two routing task with the same SeqId valid at the same period
*
* @param ctx The DispatchContext that this service is operating in.
* @param context a map containing workEffortIdFrom (routing) and SeqId, fromDate thruDate
* @return result a map containing sequenceNumNotOk which is equal to "Y" if it's not Ok
*/
public static Map<String, Object> checkRoutingTaskAssoc(DispatchContext ctx, Map<String, ? extends Object> context) {
Delegator delegator = ctx.getDelegator();
Map<String, Object> result = new HashMap<String, Object>();
String sequenceNumNotOk = "N";
Locale locale = (Locale) context.get("locale");
String workEffortIdFrom = (String) context.get("workEffortIdFrom");
String workEffortIdTo = (String) context.get("workEffortIdTo");
String workEffortAssocTypeId = (String) context.get("workEffortAssocTypeId");
Long sequenceNum = (Long) context.get("sequenceNum");
Timestamp fromDate = (Timestamp) context.get("fromDate");
Timestamp thruDate = (Timestamp) context.get("thruDate");
String create = (String) context.get("create");
boolean createProcess = (create !=null && "Y".equals(create)) ? true : false;
List<GenericValue> listRoutingTaskAssoc = null;
try {
listRoutingTaskAssoc = EntityQuery.use(delegator).from("WorkEffortAssoc")
.where("workEffortIdFrom", workEffortIdFrom,"sequenceNum",sequenceNum)
.orderBy("fromDate")
.queryList();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingTechDataWorkEffortAssocNotExist", UtilMisc.toMap("errorString", e.toString()), locale));
}
if (listRoutingTaskAssoc != null) {
for (GenericValue routingTaskAssoc : listRoutingTaskAssoc) {
if (! workEffortIdFrom.equals(routingTaskAssoc.getString("workEffortIdFrom")) ||
! workEffortIdTo.equals(routingTaskAssoc.getString("workEffortIdTo")) ||
! workEffortAssocTypeId.equals(routingTaskAssoc.getString("workEffortAssocTypeId")) ||
! sequenceNum.equals(routingTaskAssoc.getLong("sequenceNum"))
) {
if (routingTaskAssoc.getTimestamp("thruDate") == null && routingTaskAssoc.getTimestamp("fromDate") == null) sequenceNumNotOk = "Y";
else if (routingTaskAssoc.getTimestamp("thruDate") == null) {
if (thruDate == null) sequenceNumNotOk = "Y";
else if (thruDate.after(routingTaskAssoc.getTimestamp("fromDate"))) sequenceNumNotOk = "Y";
}
else if (routingTaskAssoc.getTimestamp("fromDate") == null) {
if (fromDate == null) sequenceNumNotOk = "Y";
else if (fromDate.before(routingTaskAssoc.getTimestamp("thruDate"))) sequenceNumNotOk = "Y";
}
else if (fromDate == null && thruDate == null) sequenceNumNotOk = "Y";
else if (thruDate == null) {
if (fromDate.before(routingTaskAssoc.getTimestamp("thruDate"))) sequenceNumNotOk = "Y";
}
else if (fromDate == null) {
if (thruDate.after(routingTaskAssoc.getTimestamp("fromDate"))) sequenceNumNotOk = "Y";
}
else if (routingTaskAssoc.getTimestamp("fromDate").before(thruDate) && fromDate.before(routingTaskAssoc.getTimestamp("thruDate"))) sequenceNumNotOk = "Y";
} else if (createProcess) sequenceNumNotOk = "Y";
}
}
result.put("sequenceNumNotOk", sequenceNumNotOk);
return result;
}