Using expression to compare Calendar object
Hi,
I wonder if anyone has experience to use expression to compare Calendar object. Here is my case:
Application {
Calendar applicationDate;
What I want is something like:
expression.get("applicationDate").between(startDate, endDate);
But it is seems not working this way.
Any clue?
Thanks
Hao
What error are you getting, in general this should work, however the Calendar will be printed/bound as a java.sql.Timestamp.
If you require to use java.sql.Date if you just want the date portion of the Calendar.
If your mapping for applicationDate sets the fieldClassification (i.e. is a TypeConversionMapping), then TopLink will automatically convert the Calendar value in the expression to the correct date type.
Similar Messages
-
Hi, I want to compare two objects
using the formula below
if((Integer)v.elementAt(i) == new Integer(comp.getCard(j).getValue())){but it doesn't work
I am trying to compare an element in a vector which was of a type Integer
key1 = new Integer(dk.getCard(f).getValue());note that key1 is actually a key used for a mapping
can anyone tell me how I can compare the elements in vector and the other object was an int.
Hello zainuluk,
You can not use '==' operator to compare to objects in Java, 'cause it just compare the reference of two oprands. You should use the "equals()" method, just like this:
if(Integer)v.elementAt(i).equals(new Integer(comp.getCard(j).getValue())){...}
Or you can get the int value of element in the vector to compare using '==' operator:
if(Integer)v.elementAt(i).intValue() == comp.getCard(j).getValue()){..}
Hello zainuluk,
You can not use '==' operator to compare to objects in Java, 'cause it just compare the reference of two oprands. You should use the "equals()" method, just like this:
if(Integer)v.elementAt(i).equals(new Integer(comp.getCard(j).getValue())){...}
Or you can get the int value of element in the vector to compare using '==' operator:
if(Integer)v.elementAt(i).intValue() == comp.getCard(j).getValue()){..}
I have switched from PC to Mac over a year and a half ago, and have been plagued with the "dumb" date entry boxes in iCal and now Reminders on the mac. For one, they don't show you the DAY OF WEEK for an event, it assumes you are parked on that day, but of course reality sets in and causes constant date changes for events. Picking a date in the future would be much more helpful if Apple followed some usability norms in iCal. For instance, if you are booking a flight online, those helpful little calendar objects pop up, and further, they are smart about "end dates and times" for events, knowing it can't be earlier than the start date. Apple iCal unfortunately always thinks you are creating an ALL DAY event, and when you change the start time, it creates the end time for the next day. Not very smart. Or is it me that is not very smart for constantly hawking every little data entry field for correctness. Why, oh why dear lord has Apple not given some usability attention to iCal on the mac??? At least match the interface of the iPhone with a nice little slot machine rolling control.
Is there an add in?
Is there hope that Apple will ever fix its lagging Mail and iCal apps on the Mac?
Please advise. Or just offer a kind word of consolation if there is no hope for a better interface.
In the future, Swing related questions should be posted in the Swing forum.
The code you posted is of little use since it uses custom classes so we can't see the behaviour of your code.
In general if you add a component to a Container at run time then you just use
container.revalidate()
This will invoke the LayoutManager and repaint the components in the container based on the new layout.
When using "Database diff" selecting other schemas only for compare own objects are shown too!
Hi!
For comparing lot of objects I use a priviliged account z, which can read Schema a and b.
In the compare dialog I set different from the Defaults following Options:
- step 1
- option "Maintain"
- step 3
- button "More"
- select schema a
- button "Lookup"
- mark all objects and shuttle to the right
- repeat for schema b
After the diff report is finished, schema object of account z are listed too, despite I have not selected this.
Best regards
Torsten
Ah, you're using user Z to select objects from A & B?
On step 2, do you have anything selected that you have not picked an object type for using the 'shuttle' in Step 3?
For example, if you picked, 'procedures' and then in the wizard, didn't pick ANY procedures in A or B, it will by default use ALL of the procedures in Z for the compare.
Using calendar object on prompt
I'm having prompt with two calendar objects - FROM and TO dates selection for setting report's time frame.
How can I show error message when user enter invalid date (typing directly in text box) or in case user select dates where FROM is after TO dates?
@ nir
Are you using 10g,if so i worked with the same solution couple of months back and it worked for me nor it caused performance issues.Its not JS script but just adding a IF statement to the existing sections if you have see the link.....Coming to 11g that im working still dint go to that extent to look back,i suppose it has been solved.
UPDATED POST
Coming to 11g there are many bugs.....i would suggest you to wait till march-april so next 11g R2 release is due to come at that period according to road map.
We cant predict anything saying this will be solved....same happened when 11gR1 many expectations where there but ended up with bugs and many unsolved issues iam facing.
We can do 1 thing hoping for best :)
Is it helpful?
By,
KK
Edited by: Kranthi on Jan 13, 2011 1:36 AM
Strange behaviour of Calendar Objects
Hello folks, you may not believe it but I had a really strange behaviour in my Calendar Objects:
I have 2 GregorianCalendar Objects, one instantiated by getInstance() for holding a reference for today and a second a user can pick which may or may not lie in the past. With some of my date fields it is allowed to have a past date, with others it is not, that is why I hold the reference for today.
Then, for getting to know if the picked date is in the past I set the hours, minutes, seconds and milliseconds to 0 before comparing because I was just interested in the day not the time.
And now comes what I cannot comprehend nor what I was able to fix:
In the morning hours of the day I programmed this worked great. I gave it to our testers, and some days later I got it back on my desk, it would not work. I tested again in the morning, and it workd. I was confused, let it lay around a few days and tested again, this time in the afternoon. And it worked not ... now I was really confused. Just I had no time to fix it asap and put it aside for the next morning ... when it worked again ... ???
So I started deep debugging ... and since I already got an idea it could have something to do with the daytime I worked on it in the evening.
The debugging told me that the milliseconds of the 2 Calendar objects had exactly the same time and date, just different milliseconds in the evening and in the afternoon, but not in the morning. I cannot understand why, maybe one of you?
I solved it by kicking the millisecond compare and compared year, month and day, so now it works. But it still confuses me why the milliseconds could have differed at all and why not in the morning but just in the afternoon and evening (both Objects are of the same time zone, I checked this, too).
Rommie.
I set the hours, minutes, seconds and milliseconds to 0...And you get different results in the morning and the afternoon? Okay, go to the API documentation and read about what the constant Calendar.HOUR means. Look just below it for another constant called Calendar.HOUR_OF_DAY and consider whether you should be using that instead.
PC²
Help! problem with Calendar objects.
I'm trying to figure out somebody's age based on their birthday inputed in MM/DD/YYYY format. I've created two Calendar objects; now, dob. I initialize both of them using the getInstance() method than I set the year, month, and day fields for dob to the user inputs. Then I subject the number of years between them(eg. 2005 - 1984 = 21). Then I add 21 to the year field for dob and compare that to now to see if the day has passed yet this year, and if it hasn't I would subtract 1 from 21 to get the age.
I use the before() method to see if now is before dob, which returns the answer I want except for when the dob's month is the same as now's month.
When is use 10/10/1984 I get the age as being 20 but it should be 21, however if I use any month before Oct. I get the correct age.
Here's the code I'm using, any help would be greatly appreciated.Calendar calendar1;
Calendar calendar2;
int age;
calendar1 = Calendar.getInstance();
calendar2 = Calendar.getInstance();
// the following three lines would be user input
calendar2.set(Calendar.YEAR,1984);
calendar2.set(Calendar.DAY_OF_MONTH,1);
calendar2.set(Calendar.MONTH,10);
int currentYear = calendar1.get(Calendar.YEAR);
int birthYear = calendar2.get(Calendar.YEAR);
age = currentYear - birthYear;
calendar2.add(Calendar.YEAR, age);
if(calendar1.before(calendar2))
age -= 1;
System.out.println(age);
When is use 10/10/1984 I get the age as being 20 but
it should be 21, however if I use any month before
Oct. I get the correct age.Probably because January is month 0 according to Calendar. So when you do
calendar2.set(Calendar.MONTH,10);you are actually setting the month to November.
I am using the big date calendar template in iPhoto. I am on Lion 10.7.2, macbook air. The names of the months are on each calendar page but something happens when I send the data to Apple. The names are part of the template. They are not text boxes. I lose two names on the calendar after it is sent to Apple. Apple suggested I make a pdf file of my calendar before sending it in and check to make sure every name shows. I did this with a calendar I just sent in. The calendar was correct. All names of the months were showing. After sending the data two month names disappeard because when it arrived by mail, it was incorrect. Apple looked at my calendar via a pdf file and it was incorrect. This is second time this has happened. I called Apple and they had me delete several folders in the Library folder, some preferences and do a complete reinstall of iPhoto. I have not yet remade the defective calendar. I am wondering if anyone else has had this problem?
kathy
Control-click on the background of the view all pages window and select "Preview Calendar" from the contextual menu.
You can also save the pdf as a file to compare to the printed calendar. If the two names are visible in the pdf file then the printed copy should show them. Contact Apple for a refund. Apple Print Products - Apple Store (U.S.)
How to use a custom comparator in a TableSorter?
Hi,
I want to use a custom comparator for sorting a table by a specific column.
As you possibly know, the constructor for the TableSorter class looks like this:
TableSorter(IWDTable table, IWDAction sortAction, Map comparators);
As Map is an Interface I chose Hashmap as comparator container. So, I use the put(Key, Value) method to insert my own comparator into the Hashmap in order to deliver this Object to the TableSorter constructor.
But there is an essential problem:
I assume, that the column which is to be associated with my comparator is determined by the key of the Map object from the TableSorter constructor.
Presuming this, <u>what should the map key be/look like?</u>
An Integer counted from the columns? The column header as String? Whatever? Or am I on the wrong way?
PS:
Hours of search did not lead me to some kind of documentation or javadoc of the TableSorter class! This can't be, does someone have a link please?
Thanks a lot for any help.
(sorry Mrutyun, this did not help.)
Ok, I solved it; let me share it with you:
public class ExampleView
public static void wdDoModifyView(IPrivateExampleView wdThis, IPrivateExampleView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
* A custom Comparator class is used for sorting by Severity.
* An Object of it is delivered to an object of a Map class to be delivered to the TableSorter constructor.
* The Map class consists of key-value pairs, and the TableSorter must accept the Key of it
* because he uses it to assign the mapped Comparator to the column of the table to be sorted!
* And this is done with the ID of the Element, which shall be sorted with the Comparator, used as Map Key.
* All other columns of the assigned tables will be sorted by default Comparators.
IWDTable table = (IWDTable) view.getElement("[TableName]");
HashMap tableComps = new HashMap();
tableComps.put(view.getElement("[ColumnName]").getId(), new MyComp(wdContext.currentExampleElement())); //The map key value I looked for is the ID of the Element of the Column!
wdContext.current/*yourContextNode*/Element().setTableSort(
new TableSorter(table, wdThis.wdGetSortTableRowAction(),
tableComps)); //Insert HashMap with the new Comparator
public void onActionSortTableRow(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionSortTableRow(ServerEvent)
wdContext.currentConfigurationElement().getTableSort().sort(wdEvent, wdContext.nodeOpenIncident());
//@@end
As you see, the Column which is to be sorted by the custom Comparator "MyComp", is clearly assigned to it. Thus, is will only be used when sorting by this column is done.
The "inActionSort" method is as usual.
My Comparator sorts a column which contains variables of a "SimpleType" with an enumeration. (If you need help with this, feel free to write me.) To achieve this, the Comparator needs to know what this SimpleType consists of. That's why I deliver this Element per Constructor to it.
public class MyComp implements Comparator
MappedNodeElement element;
public SeverityComp(I/*one*/Element element)
this.element = element;
public SeverityComp(I/*another*/Element element)
this.element = element;
public int compare(Object severity1, Object severity2)
Because MappedNodeElement is such abstract, it can be used by several different Tables, provided they use the same SimpleType.
Concerning my quest for this resolution, I hope this is helpful.
null
Convert a calendar object to a date object
hi all...i use a calendar to select date and i want to convert the Calendar object returned to a date object ..how could i do that ?? i use the following lines of code but the Date object returned is not correct ..i mean it's not the one i chose from the calendar
Date selectedDate=new Date();
selectedDate=(calendar1.getTime());
Any one could help....thank you
Show us the code where you set the calendar to your desired value. Calendar1.getTime()
should return the relevant date.
Date change problem in Calendar object
Hi i have a calendar object for date representation.
When i need to go ahead a day i use a add method that adds a day to the Calendar object, and if the date is out of range it adjustes proerly to the next montha and proper date in that next month.
But it fails for 2 instances in a year.
From May to June and From October to November.
This i think is happenning because of the Daylight saving times in the May and October.
I try to go from May to June but it never does on it's own !! Do i have to explicitly check that for those 2 months or there is any other method ?
How can i get over it ??
Please help me with this.
Shailendra
Hi
There may be some other reason for it, coz Day light savings starts in last week of March, not in May.
And day light savings ends in Last week of October
Suresh
How to calculate number of days between Calendar objects
Hi,
I need to calculate the number of days between two Calendar objects. Here is some sample code:
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
// get a calendar that represents a day in the past
Calendar aDayInThePast = getADayInThePast();
aDayInThePast.set(Calendar.HOUR_OF_DAY, 0);
aDayInThePast.set(Calendar.MINUTE, 0);
aDayInThePast.set(Calendar.SECOND, 0);
aDayInThePast.set(Calendar.MILLISECOND, 0);
// how can I calculate the number of days ago this was??
//it would also be useful to get back a negative number if the day is in the future
My favorite answer so far is reply 15 by Marc__: http://forum.java.sun.com/thread.jspa?threadID=488668&start=15
Hi, I'm not new to Java, but this seems like the best place for this question: I have some code dealing with parsing and reading schedules:
Calendar now = Calendar.getInstance();
Calendar startDateTime = (Calendar) startTime.clone();
Calendar stopDateTime = (Calendar) stopTime.clone();
startDateTime.set(Calendar.YEAR, now.get(Calendar.YEAR));
startDateTime.set(Calendar.MONTH, now.get(Calendar.MONTH));
startDateTime.set(Calendar.DATE, now.get(Calendar.DATE));
stopDateTime.set(Calendar.YEAR, now.get(Calendar.YEAR));
stopDateTime.set(Calendar.MONTH, now.get(Calendar.MONTH));
stopDateTime.set(Calendar.DATE, now.get(Calendar.DATE));
if (scheduleType == 0) //weekly
for (int i = 0; i < schedule.length(); i = i + 3)
//System.out.println (TIMEFORMAT.format(startDateTime.getTime()));
startDateTime.set(Calendar.DAY_OF_WEEK, Integer.parseInt(schedule.substring(i, i + 1)));
stopDateTime.setTime(startDateTime.getTime());
stopDateTime.add(Calendar.DATE, Integer.parseInt(schedule.substring(i + 1, i + 3)));
System.out.println (TIMEFORMAT.format(startDateTime.getTime()) + " " + TIMEFORMAT.format(new Date()) + " " + TIMEFORMAT.format(stopDateTime.getTime()));
...My out put is:
2008-11-24 09:47:00.000 2008-11-10 10:26:14.981 2008-11-27 15:00:00.000
Which is not what I though I'd get (startDateTime and stopDateTime should be 2008-11-10, 2008-11-13).
However, if I uncomment the "System.out.println(TIMEFORMAT.format(startDateTime.getTime()));" right after the if statement, my out put becomes:
2008-11-10 09:47:00.000 2008-11-10 10:27:33.924 2008-11-13 15:00:00.000
Which is what I want.
This makes no sense to me, that System.out.println is apparently "changing" something. The closet I can figure is that System.out.println gives more time for something to do something. Shrugs.
I figure I can bandaid it by setting the startDateTime/stopDateTime to (Calendar) now.clone(), and then setting the specific hour, minute, second to the stopTime/startTime instead, but this is really bugging me.
Thanks for any help.
I've been working with java for 4-5 years, and I'm studying CS for my major, so I thought myself at least not new, but I suppose if the experienced say so, then I guess my self-estimation was wrong. Well, this is a good reality check.
Before anything else though, about what you said about .getTime() ("It is also setting startDateTime to the current time"). I'm under the impression that .getTime() get's the Calendar object's current time as a Date object (which as far as I've used, seems to be true) and also calculates the millisecond value. So if my Calendar is set to "January 2000", when I call .getTime() on it, do I get back a Date object set to "January 2000" (what I set it to) or "November 2008" (today's date)?
As for the program, I read in a schedule, a start_time, a stop_time (as well as the schedule_id, but that's not important) from a database, and create a schedule object. Then in one method of my Schedule object I check if the current time is in the schedule. I create startDateTime and stopDateTime objects on the fly since if the program runs overnight to the next week, a startDateTime, stopDateTime created at initialization will be wrong.
Here's a very heavily stripped down recreated version with a main and the test case I was using so you can run this.
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Schedule2
//date formatter
private static final SimpleDateFormat TIMEFORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String schedule;
Calendar startTime = Calendar.getInstance();
public Schedule2(String schedule, Date startTime)
this.schedule = schedule;
this.startTime.setTime(startTime);
public boolean nowInSchedule()
Calendar now = Calendar.getInstance();
Calendar startDateTime = (Calendar) startTime.clone(); //set the time values to correct values
startDateTime.set(Calendar.YEAR, now.get(Calendar.YEAR)); //set the year/month/date values to correct ones
startDateTime.set(Calendar.MONTH, now.get(Calendar.MONTH));
startDateTime.set(Calendar.DATE, now.get(Calendar.DATE));
for (int i = 0; i < schedule.length(); i = i + 3)
//System.out.println(TIMEFORMAT.format(startDateTime.getTime()));
startDateTime.set(Calendar.DAY_OF_WEEK, Integer.parseInt(schedule.substring(i, i + 1))); //sets current day_of_week to the one in the schedule
System.out.println(TIMEFORMAT.format(startDateTime.getTime()));
//when I check the startDateTime.getTime(), here is when I get the wrong date (2008-11-24 instead of the 10th)
return false;
public static void main(String [] args)
Calendar a = Calendar.getInstance();
a.set(1899, 12, 30, 10, 50, 0);
Schedule2 sked = new Schedule2 ("203", a.getTime());
System.out.println(sked.nowInSchedule());
}So in my test case, I had "203" as the schedule, meaning every Monday until Thursday (first digit is Monday, second two is the number of days the schedule lasts) and the start_time as "30/12/1899 10:50:00 AM".
I expected to get back "2008-11-10" since this week's Monday falls on the second, but instead I got "2008-11-24".
I did read the Calendar API, but I suppose I didn't understand it fully. .set() updates the fields, but not the millisecond value. So, maybe .set(Calendar.DAY_OF_WEEK, ...) is not doing what I think it is doing because the millisecond value isn't computed yet, and .set(Calendar.DAY_OF_WEEK, ..) seems more complicated than just setting straight YEAR/MONTH/DATE.
I'm using Java 1.4.2 BTW.
Edited by: Yi.Liu on Nov 10, 2008 12:57 PM
Calendar object issues ... recompute remaining fields after change?
Hello all. I'm doing date manipulation and arithmetic, but I'm running into a problem.
I'm taking a date provided by a user and comparing it the current date. However, it's the month-end that I'm interested in.
I'm already creating GregorianCalendar objects from each one, and doing the set on the DAY_OF_MONTH field to the value from getActualMaximum(DAY_OF_MONTH).
The problem I'm having is that when dealing two dates from the same month, the two Calendar objects are >NOT< returning as EQUAL. After converting each object to a Date and running compareTo() (Side Bar: Why isn't compareTo() available in the Calendar class?) I'm not getting zero.
I tried a toString() on the two objects, and I can see that some of the fields are not exact ... the time field is "?", WEEK_OF_YEAR, WEEK_OF_MONTH are different, etc. I can see the protected method complete() in the API, but attempts to execute them (gcCurrDate.complete()) yield compile errors stating the method is not visible.
So how does one ask the system to fill in the remaining fields?
Thanks!
Steve
According to the API docs for Calendar:
"set(f, value) changes field f to value. In addition, it sets an internal member variable to indicate that field f has been changed. Although field f is changed immediately, the calendar's milliseconds is not recomputed until the next call to get(), getTime(), or getTimeInMillis() is made."
Hi,
I need to get a calendar object without displaying the time (hh:mm) field. Can smone help me with this??
Thanks in advance
Thanks for the replies..but my requirement is a
calendar object which i need to set in one of the
existing bean class set methods which takes in only a
calendar object (I cant modify the method signature).
I am pasting my code below..
The situation is : I get data from database as a
string read from a file which is then converted into
a format yyyy-MM-dd using a simple date format. This
returns a date object which i need to convert to
calendar without showing the time fields. The prb is
it is showing the GMT diff as default.
public static Calendar dateString2Calendar(String s)
throws ParseException {
static SimpleDateFormat df = new
SimpleDateFormat("dd-MMM-yy");
static SimpleDateFormat df1 = new
SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
1 = null;
Date d2 = null;
String S1 = null;
d1 = df.parse(s);
S1 = df1.format(d1);
d2 = df1.parse(S1);
cal.setTime(d2);
return cal;
Req output : 2004-09-07
Current output : 2004-09-07+05:30
00:00 also not allowed in the output :(The Calendar object represents a particular moment in time - it does not have a format and it always has a time portion. Do not use the toString() method to display it - if you use the System.out.println() method to display it, the toString() method is being still being called. Format the display using SimpleDateFormat as suggested.
Maybe you are looking for
-
Hi, I need to resolve 2 issues related to BEX issue 1 when I am looking for a username I need to type the exact combination of upper and lower case letters. e.g I have JOHN in the username MD and if I type John, I don't get any result. issue 2 I wou
-
Error while running the reports
Dear all, when our techno-functional users are trying to run any report they are getting the following error message. "APP-FND-00268: please specify a valid printer Either you have not specified a printer for your report, or the printer name you have
-
Report painter libaries and report group
Hi, I would like to seek advice on the relationship of libaries and report group. 1 in GRR2 navigation, i can see libary and report but i do not see report group in the navigation structure. So I would like to know what is the purpose of report group
-
JMS Adapter not picking file in PI7.0
Hello, I am working jms to jms scenario on PI7.0 Service Pack13. file is not able to pick up sendar JMS Channel. I am using WebSphereMQ Transport Protocol. JMS drivers are installed. ports and protocals are correct. I checked all parameters of JMS Ad
-
User exit or BADI for VL01N and VL02N
Hi Experts, My requirment is while creating and changing delivery, change inco terms of delivery when some condition satisfy. can you any one tell me any user exit or badi , i will write the logic to change inco terms based some condition. Regards Ja