This is an archive of the Maximo Yahoo Community. The content of this pages may be a sometimes obsolete so please check post dates.
Thanks to the community owner Christopher Wanko for providing the content.
I recently encountered a similar issue-this is what I came up with (and, yes, I know that you don't need semicolons at the ends of lines in jython...)
from psdi.server import MXServer;
from psdi.mbo import MboConstants;
from java.util import Date;
from java.text import SimpleDateFormat;
from java.util import Calendar;
errflag = 0;
vStartD = mbo.getDate("ACTUALSTART");
vFinishD = mbo.getDate("ACTUALFINISH");
vStartT = mbo.getDate("STARTTIME");
vFinishT = mbo.getDate("FINISHTIME");
verror = chr(10) + chr(10);
if (vFinishD != None and vFinishD > MXServer.getMXServer().getDate()):
errflag = 1;
verror = verror + "The <b>Actual Finish</b> cannot be in the future</b>." + chr(10) + chr(10);
if (vStartD != None and vStartD > MXServer.getMXServer().getDate()):
errflag = 1;
verror = verror + "The <b>Actual Start</b> cannot be in the future</b>." + chr(10) + chr(10);
if (vStartD != None and vFinishD != None and vStartT != None and vFinishT != None) and ((vStartD > vFinishD) or (vStartD == vFinishD and vStartT > vFinishT)):
errflag = 1;
verror = verror + "The <b>Actual Start</b> cannot be greater than the <b>Actual Finish</b>." + chr(10) + chr(10);
if (errflag == 0 and vStartD != None and vFinishD != None and vStartT != None and vFinishT != None):
D = SimpleDateFormat("MM/dd/yy").format(mbo.getDate("ACTUALSTART"));
T = SimpleDateFormat("HH:mm:ss").format(mbo.getDate("STARTTIME"));
scal = Calendar.getInstance();
scal.setTime(Date(D + " " + T));
S = SimpleDateFormat("MM/dd/yy HH:mm:ss").format(scal.getTimeInMillis());
D = SimpleDateFormat("MM/dd/yy").format(mbo.getDate("ACTUALFINISH"));
T = SimpleDateFormat("HH:mm:ss").format(mbo.getDate("FINISHTIME"));
fcal = Calendar.getInstance();
fcal.setTime(Date(D + " " + T));
F = SimpleDateFormat("MM/dd/yy HH:mm:ss").format(fcal.getTimeInMillis());
if (Date(S) > MXServer.getMXServer().getDate()):
errflag = 1;
verror = verror + "The <b>Actual Start</b> cannot be in the future</b>." + chr(10) + chr(10);
if (Date(F) > MXServer.getMXServer().getDate()):
errflag = 1;
verror = verror + "The <b>Actual Finish</b> cannot be in the future</b>." + chr(10) + chr(10);
if (Date(S) > Date(F)):
errflag = 1;
verror = verror + "The <b>Actual Start</b> cannot be greater than the <b>Actual Finish</b>." + chr(10) + chr(10);
if (errflag == 0):
vDuration = Date(F).getTime() - Date(S).getTime();
vHours = int(vDuration.longValue() / 1000 / 60 / 60);
vMinutes = int(vDuration.longValue() / 1000 / 60) - vHours * 60;
mbo.setValue("DURATION", str(vHours) + ":" + str(vMinutes), 11L);
else:
mbo.setValue("DURATION", "", 11L);
else:
mbo.setValue("DURATION", "", 11L);
## THROW ERROR ##
if(errflag==1):
error=verror
errorgroup="GRE";
errorkey="ACT_STATUS";
params=[error];
NOTICE TO RECIPIENT: The information contained in this message from
Great River Energy and any attachments are confidential and intended
only for the named recipient(s). If you have received this message in
error, you are prohibited from copying, distributing or using the
information. Please contact the sender immediately by return email and
delete the original message.