Calendar bug setting DAY_OF_WEEK in JDK 1.3.1

I cannot find a workaround for this bug:
import java.util.Calendar;
import java.util.Date;
public class Mescal {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.set(2002, Calendar.FEBRUARY, 2); // Sat, 2 Feb 2002
cal.set(Calendar.MILLISECOND, 0);
Date d = new Date(cal.getTime().getTime());
Calendar cal2 = Calendar.getInstance();
cal2.setTime(d);
cal.set(cal2.get(Calendar.YEAR),
cal2.get(Calendar.MONTH),
cal2.get(Calendar.DATE));
// cal.set(Calendar.WEEK_OF_MONTH, cal2.get(Calendar.WEEK_OF_MONTH));
System.out.println("start: " + cal.getTime() + " : " + d);
cal.setTime(d);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println("Set weekday: " + cal.getTime());
cal.set(Calendar.HOUR_OF_DAY, 0);
System.out.println("Set hour: " + cal.getTime());
cal.set(Calendar.MINUTE, 0);
System.out.println("Set minute: " + cal.getTime());
cal.set(Calendar.SECOND, 0);
System.out.println("Set second: " + cal.getTime());
The output is:
start: Sat Feb 02 11:19:18 CET 2002 : Sat Feb 02 11:19:18 CET 2002
Set weekday: Mon Jan 28 11:19:18 CET 2002
Set hour: Mon Dec 31 00:19:18 CET 2001
Set minute: Mon Nov 26 00:00:18 CET 2001
Set second: Mon Oct 29 00:00:00 CET 2001
The problem arises when setting the weekday takes the date back to the previous month. For example, starting off with Feb 9:
start: Sat Feb 09 11:20:50 CET 2002 : Sat Feb 09 11:20:50 CET 2002
Set weekday: Mon Feb 04 11:20:50 CET 2002
Set hour: Mon Feb 04 00:20:50 CET 2002
Set minute: Mon Feb 04 00:00:50 CET 2002
Set second: Mon Feb 04 00:00:00 CET 2002
This has been fixed in JDK1.4Beta2, but obviously we're not going to pin our application on that. There's also a problem with 1.4 that I'll get to in a bit.
The second calendar attempt (seen in code sample but ultimately not used) doesn't make any difference. Although if you don't use setTime and only initialize the calendar using set(int year, int month, int day) then setting the weekday sets it to the 1st week of the month.
For example:
Calendar cal = Calendar.getInstance();
cal.set(2002, Calendar.FEBRUARY, 13); // Sat, 2 Feb 2002
cal.set(Calendar.MILLISECOND, 0);
System.out.println("start: " + cal.getTime());
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
//rest of code is same
produces:
start: Wed Feb 13 11:38:20 CET 2002
Set weekday: Mon Feb 04 11:38:20 CET 2002
Set hour: Mon Feb 04 00:38:20 CET 2002
Set minute: Mon Feb 04 00:00:20 CET 2002
Set second: Mon Feb 04 00:00:00 CET 2002
The bug (?) in JDK1.4Beta2:
if you set WEEK_OF_YEAR, then the date is advanced one.
Calendar cal = Calendar.getInstance();
cal.set(2002, Calendar.FEBRUARY, 13); // Sat, 2 Feb 2002
cal.set(Calendar.MILLISECOND, 0);
cal.setFirstDayOfWeek(Calendar.SUNDAY);
Date d = new Date(cal.getTime().getTime());
Calendar cal2 = Calendar.getInstance();
cal2.setTime(d);
// cal.set(cal2.get(Calendar.YEAR),
// cal2.get(Calendar.MONTH),
// cal2.get(Calendar.DATE));
cal.set(Calendar.WEEK_OF_YEAR, cal2.get(Calendar.WEEK_OF_YEAR));
// System.out.println("start: " + cal.getTime() + " : " + d);
// cal.setTime(d);
System.out.println("start: " + cal.getTime());
Gives you:
start: Thu Feb 14 11:41:37 CET 2002
Set weekday: Mon Feb 11 11:41:37 CET 2002
Set hour: Mon Feb 11 00:41:37 CET 2002
Set minute: Mon Feb 11 00:00:37 CET 2002
Set second: Mon Feb 11 00:00:00 CET 2002
If you comment out the line cal.set(Calendar.WEEK_OF_YEAR
then the first line of output reads:
start: Wed Feb 13 11:38:17 CET 2002
An unholy mess.

Hi,
I had the same bug as you one week ago... though i never come up with a neat solution, i used several loops to counter this. Its works nicely, but the logic is messy. Here's the code:
Calendar c =new GregorianCalendar();
int first=2002;               
int second=2;               
c.set(Calendar.YEAR,first);
c.set(Calendar.MONTH,second-1); //setting it to feburary
//getting the month after i set
int m = c.get(Calendar.MONTH);
//testing if it has 31 days in the month     
c.set(Calendar.DATE,31);      
//if the month doesnt have 31 days, the month will be
//march as java set it the the next month     
int m1 = c.get(Calendar.MONTH);      
int d = c.get(Calendar.DATE);
System.out.println("month1 is "+m1);
if(m1!=m)
//if m and m1 doesnt match means the month
//doesnt have 31 days
{//if
     //set the month back to the desire month
     c.set(Calendar.MONTH,second-1);
     //test the month for 30 days               c.set(Calendar.DATE,30);
                         m1 = c.get(Calendar.MONTH);
                         d = c.get(Calendar.DATE);
                         System.out.println("month1 is "+m1);
     if(m1!=m)
                              {//if
                                   c.set(Calendar.MONTH,second-1);
                                   c.set(Calendar.DATE,29);
                                   m1 = c.get(Calendar.MONTH);
                                   d = c.get(Calendar.DATE);
                              System.out.println("month1 is "+m1);
                                   if(m1!=m)
                                   {//if     
                                   c.set(Calendar.MONTH,second-1);
                                   c.set(Calendar.DATE,28);
                                   m1 = c.get(Calendar.MONTH);
                                   d = c.get(Calendar.DATE);
System.out.println("month1 is "+m1);
                                                                           }//end if
                              }//end if
}//end if
}//end if     

Similar Messages

  • IPhone calendar appointments set to local calendar, and need to switch to exchange calendar. Have to edit each appointment one at a time and change to exchange calendar. Is there any method to edit all appoints in my calendar at once?

    iPhone calendar appointments set to local calendar, and need
    to switch to exchange calendar. Have to edit each appointment one at a time and
    change to exchange calendar. Is there any method to edit all appoints in my
    calendar at once and change the calendar setting?

    Not sure this will work but if you go into the Keyboard preferences, then click the Keyboad Shortcuts tab, and then the '+', you can add your own shortcuts for any application.  I am not sure what happens if you try to override an existing shortcut since I haven't tried using this.
    Edit/Update:
    Probably against my better judgement I'll also throw this out there - there's an Unsanity haxie called Menumaster which might also allow you to do what you want.  Against my better judgement because personally I stay clear of haxies.  It's (all haxies) probably almost certain to break in Lion.  They always do with each major release.

  • Calendar Bug? Is anyone experiencing this?

    I have an iphone 4s (ATT) running ios 6.
    I create a calendar event, set my availability to free, and set alerts
    I then invite someone to the event
    Everything is fine until they accept the event
    Once they accept or decline the event, it sets my availability back to busy and the alerts I set go back to the default
    Is this normal? I believe it was doing this on ios 5 as well?

    After a restart of my iPhone this issue seems to have gone away.

  • HT5642 I get a unable tO download messge when i try to download ios6.1. I need ios612 to fix calendar bug....the message i get says that unable to download because no longer connected to internet....i am connected to the internet all along

    I get a unable tO download messge when i try to download ios6.1. I need ios612 to fix calendar bug....the message i get says that unable to download because no longer connected to internet....i am connected to the internet all along

    1. Try reinstall iLIfe 09 from your install disk
    To re-install iPhoto
    1. Put the iPhoto.app in the trash (Drag it from your Applications Folder to the trash)
    2. Download it from the App Store to reinstall It's on your Purchases List* there.
    For older versions that have been installed from Disk you'll need these additional steps:
    2a: On 10.5:  Go to HD/Library/Receipts and remove any pkg file there with iPhoto in the name.
    2b: On 10.6: Those receipts may be found as follows:  In the Finder use the Go menu and select Go To Folder. In the resulting window type
    /var/db/receipts/
    2c: on 10.7 or later they're at
    /private/var/db/receipts
    A Finder Window will open at that location and you can remove the iPhoto pkg files.
    3. Re-install.
    If you purchased an iLife Disk, then iPhoto is on it.
    If iPhoto was installed on your Mac when you go it then it’s on the System Restore disks that came with your Mac. Insert the first one and opt to ‘Install Bundled Applications Only.
    *Sometimes iPhoto is not visible on the Purchases List. it may be hidden. See this article for details on how to unhide it.
    http://support.apple.com/kb/HT4928
    One question often asked: Will I lose my Photos if I reinstall?
    iPhoto the application and the iPhoto Library are two different parts of the iPhoto programme. So, reinstalling the app should not affect the Library. BUT you should always have a back up before doing this kind of work. Always.
    If that fails, then you're reinstalling the OS.

  • My calendar is set at "read only" on my iPhone how do i get access

    My calendar is set at "read only" on my iPhone how do i get access

    Contact the person who 'gave' you the iPhone and have follow this link:
    Prepare your device to sell or give away
    If they do not have the AppleID and passcode requested, turn the iPhone
    in to your local authorities as it is stolen or lost, and in either case it is not yours
    nor does it belong to the person who gave it to you.
    There is no workaround for Activation Lock.
    iCloud: Find My iPhone Activation Lock in iOS 7 & later
    http://support.apple.com/kb/HT5818?viewlocale=en_US&locale=en_US
    http://support.apple.com/kb/TS4515

  • [svn] 3493: Fix bug setting focus into an A. 2 application that is in a dialog.

    Revision: 3493
    Author: [email protected]
    Date: 2008-10-06 13:40:22 -0700 (Mon, 06 Oct 2008)
    Log Message:
    Fix bug setting focus into an A.2 application that is in a dialog.
    QE: YES
    Doc:
    Checkintests: Marshall Plan mustella tests
    Reviewer: Carol
    Bugs: SDK-17177
    SystemManager.as
    On mouse down, change the test from "the click was in a bridged application", to "the click is in a bridged application and it has the same focus manager as the document". A bridged application that is in a dialog will have a different focus manager than the document.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-17177
    Modified Paths:
    flex/sdk/branches/3.0.x/frameworks/projects/framework/src/mx/managers/SystemManager.as

    Thanks Jutapa.
    When I ran the DPC Latency Checker, there were no significant hiccups, and nothing abnormal at all when the skips occurred. The PCI Latency Tool had no effect on the issue, either (I tried many different latency options, between 0 and 248). But maybe they'll help other people with this or similar problems!
    Besides that, I tried logging huge amounts of data with the performance monitor and there's no consistent abnormalities at the times the skips occur as far as CPU usage or any other measurable variables go.
    I'll check out http://musicxp.net! I'd tried fresh installs and disabling all unnecessary system services and startup programs before and it also had absolutely no effect, but that's probably not what MusicXP.net advises, so I'll take a look. Thanks!

  • My macbook pro for over an hour has on the screen report bug, setting up  and processing log in

    my macbook profor over an hour has on the screen report bug, setting up and processing log in? what should i do

    my macbook profor over an hour has on the screen report bug, setting up and processing log in? what should i do

  • Calendar bug - half-year view glitch - Z10 10.2.1

    BB10 calendar app's half-year view display has a bug that seems pretty disturbing because it is so basic:
    1) Open calendar to month view (this is my default)
    2) Swipe the content pane down to reveal the half-year view
    3) Tap the current month - this dismisses the half-year view and takes you to the month view
    4) Swipe the content pane down again to reveal the half-year view, then swipe right to view the prior half-year, then swipe left to get back to the current half-year.
    The dates shown for the current month in the half-year view will be shifted.
    I noticed this bug in April 2014.  The 1st of the month fell on a Tuesday.  But after doing the above described swipe sequence, the dates shown for just April, in the half-year view, are shifted forward, so that it incorrectly shows April 1 as falling on a Wednesday.  As I'm reporting this on April 30, it's unlikely to get reviewed by someone at BlackBerry in April, and I didn't try re-setting my device date to different months to see if the bug manifests for months other than April.  So, if a BlackBerry reviewer is going over this bug report later this year and cannot get the bug to manifest, they should re-set their device date to some date in April 2014.  However, as they investigate the bug, they should probably try to get it to manifest in other months, and maybe also in a leap year.
    Note that if you do two right swipes in the half-year view, to go back to the prior year, then do two left swipes to again get back to the current year, the dates for the current month then line up correctly.
    A bug like this really makes me lose trust in my calendar (a calendar is not a new research problem in software development, so if this is broken, what else is broken?)
    Device/OS details:
    STL100-3
    Software release:  10.2.1.2156
    OS Version: 10.2.1.2228

    Confirmed that the same bad behavior is there now that the calendar has rolled forward to May.
    Like I said this raises the question of what else is broken in the basic functionality of an essential app.
    BlackBerry folks reading this - hope to you see you reproduce the bug, and acknowledge ingestion of a bug report into your internal bug tracking system, for priority fix on next OS release.
    Others reading this, if you reproduce the bug (should be easy) - please add comments as you see fit, to get BlackBerry's attention on this one.

  • Issue with Gregorian Calendar and setting Day of the week

    Hi
    This may have a simple solution, but its currently got me stumped. Basically, after some calculation I determine the date that a particular event should occur on. These events are listed in a JTable where the column headers are the dates of the beginning of the weeks. In order to place my calculated event in the correct column I create a Gregorian Calendar, set it to the date of the event and then set the day of the week to the beginning of the week. Normally this works fine but for a few instances, rather than getting the date at the beginning of the week, I get the date thats the beginning of the next week.
    As a quick example, to kind of illustrate my problem:
    I determine that the date of the event is 27/06/2006 which is a Tuesday.
    I want this event to appear in the column headed 25/06/2006, the date of the beginning of the week.
    In fact it appears in the column headed the 02/07/2006 which is the beginning date of the following week.
    Is there anyway to get it so when I set the day to the first day of the week it goes to the beginning of the current week rather than the beginning of the next week?
    Any suggestions would be gratefully recieved as I'm currently struggling to think of any.
    Thanks

    Hi, I dont say Monday is the begining of the week. At least I dont think I do.
    As for code I'll post the conversion bit which is:
    for (int i = 0; i < areaNameSelectionTable.getRowCount(); i++) {
    GregorianCalendar conversionCalendar = new GregorianCalendar();
    conversionCalendar.setTime((java.util.Date) prioritiesTable.getValueAt(i, 10));
    conversionCalendar.set(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.SUNDAY);
    }//end for loopI then create a string from the GregorianCalendar in the format DD/MM/YYYY and compare that with the headers of my table columns (Also dates in the format DD/MM/YYYY) When they match thats the column this particular event should appear in. I can post this code if necessary, but I dont know if its relevant.
    Thanks

  • How do I stop calendar from setting a second alert one day before?

    I have iOS 7.0.6 with calendar synced to my gmail account with CalDAV. When I create a new event in the calendar on my iphone, I set either a single alert or none. When I check back a few seconds later, the alert I set has become the "second alert," and the first alert is set to "one day before." Google calendar correctly shows a single alert, the one I set. If I then delete the first alert, it stays deleted. But then if I edit the even in google calendar, the "one day before" alert reappears on the iPhone. (Though still not on Google calendar.)
    It's driving me batty with all of these false alarms that are actually for tomorrow's activities. Is there a way to set alarms in iOS 7, or is that just a sacrifice we have to put up with to fix the iOS SSL bug? Should I set the current date in my iPhone to be one day late? 

    Settings > Mail Contacts, Calendars.
    Scroll down to Calendars and this sets default alert times.
    If you add an alert to a new appt, it is in addition to the default alert time.
    Either turn off default alert time or set the default alert time to when you want you want & don't add alert to the event when you create it

  • Is this a Calendar bug?

    If I set a day to 30th April 2008 and add one day, I obtain 31st April, which is a day that does not exist. Is this a bug?:
    import java.util.Calendar;
    public class DateTest
         public static void main(String[] args)
              Calendar myDay = Calendar.getInstance();
              myDay.set(2008, 4, 30);     // 30th April
              System.out.println("30th April: " +
                   myDay.get(Calendar.DAY_OF_MONTH) + " " +
                   myDay.get(Calendar.MONTH) + " " +
                   myDay.get(Calendar.YEAR) + " "
              myDay.add(Calendar.DATE, 1);     // Adds one day
              System.out.println("Next day: " +
                   myDay.get(Calendar.DAY_OF_MONTH) + " " +
                   myDay.get(Calendar.MONTH) + " " +
                   myDay.get(Calendar.YEAR) + " "
    }

    meacod wrote:
    jwenting wrote:
    I once did, but that was in a product that hadn't been on the market in that shape and version for a decade so it's quite possible for the problem to not have been fixed in that version (and there was no widespread internet availability for people to easily and quickly communicate with the producers)...I discover bugs in windows all the time... ;)I have to agree with that.
    Edited by: Java_Is_Good on May 6, 2008 12:00 AM

  • Found another Belle calendar bug (Nokia, when is B...

    I know, Nokia does not react here but writing to Dutch Nokia Care is no use: either no answer or a standard answer like "Your C6-01 is a high quality business phone with advanced features ... blah blah blah".
    But okay, found another bug in the Belle calendar. In the calendar widget to be precise: I have a easy week, no appointments. Next appointment is Monday 12 March at 09:15. Much to my surprise I did see the next thing in my calendar widget this morning Monday 5 March: at the top "monday" and below that 09:15 Doctor. I see that today, on Monday the 5th while that appointment is set for Monday the 12th. But that bugged calendar widget is not showing a date, just "monday".
    So besides the stupid 1 line mention bug, it also shows info that is confusing to say the least.
    So please Nokia, fix the calendar!!
    (and no, I do not want that ComingNext app )

    Export the region as an audio file first. Right-click the track select Export as audio file.
    Then import the track into the new project.
    Alternately, do a Save As of the project as a different file name.
    Re-open and rearrange the tracks as you please.
    Hope that helps.
    Message was edited by: Beatoven

  • IPhone Calendar Bug

    I would report a bug in the iPhone calendar.
    today i've setted an "October 31" event and I setted the monthly repeat of the event, but the result was that the event is repeated only for the 31 days months (such as December, January, ecc) and does not appear in the months with 30 day or less (such as November, February ecc)
    I reported this bug to Apple, and I hope they can find a solution to this problem.

    I found a solution. When using gmail.com follow these steps to fix it:
    http://www.google.com/support/mobile/bin/answer.py?answer=138740&topic=14252
    Cheers,
    Zdary

  • Syncing iPhone and Outlook Calendar - bug?

    I have an issue syncing my iPhone 3G Calendar with Outlook’s Calendar (Outlook 2007). In general, the sync works fine, but: If I delete the current (ie first) instance of a repeating event in Outlook, when I sync, my iPhone will still display ALL instances of that event, including the ‘deleted’ one.
    I have verified that this is because the iPhone is syncing the event based on its start date in Outlook, which will include the ‘deleted’ event, rather than what actually is shown as still a valid event in the calendar (which of course is what I want).
    I am guessing that this is just because both manufacturers are pursuing a different methodology, but the bottom line is that iPhone claims it will sync properly, so I’d call it a bug.
    I have a workaround, in that I can delete events from the Outlook calendar by changing the start date to the current one I wish to display, but this is cumbersome and of course takes more time. Is there a more elegant workaround? Or am I just doing something wrong?

    When you decide to sync the second computer to the iphone, itunes will ask you if you want to merge or replace the data.
    In the merge, data will be transfered both ways.
    So, when you say separate, you can sync them one at a time, but in the end, all the events will be the same on both computers and iphone. Because itunes keeps merging the data.

  • IOS 7 calendar bugs

    iOS 7 calendar on iPhone is not showing notifications for today or scheduled events for tomorrow. Is anyone experiencing this problem?

    Bug in monthly view.
    If I'm viewing the current month, all is fine. (So far for Sep and Oct). The top left hand corner labels the current month correctly and in bold. Eg. October 2013. I'll call this the (monthly) Label.
    But if I scroll forward to view future months, the Label displays the month incorrectly, lagging by a month.
    For example. I'm viewing the whole of January's calendar but the label would still be December.
    I have to scroll till January is almost out of view ( and Feb coming into view) before the label indicates January. By then, the little 'Feb' in 'Feb 1' has disappeared.
    And I would see Feb dates indicated as January.
    This issue is unstable. When I first got to ios 7, the labeling issue was apparently from viewing the current month.
    Now, it seems to behave for the current and next month before it goes haywire again.
    So please do scroll to many months ahead to check if you have this bug.

Maybe you are looking for

  • OS error in starting service OracleMTSRecoveryService

    I am facing the Following Problem when Installing Oracle 11g Release2 database at Microsoft Window 32-bidt OS error in starting service OracleMTSRecoveryService Note: Once I have already ionstalled this database on same machine and after that I delet

  • How can I determine what speed my ram is running at?

    ?

  • Shared components (multiple parents)

    Hi, I have posted a question in the AWT section, but it relates to Swing too, so I'm posting a link here. Please take a look: http://forum.java.sun.com/thread.jspa?threadID=786181&tstart=0 Thanks.

  • How to add fonts to our Application

    hi all, I am developing an Application in which i want to have different font for my Application.Can anybode please tell me the way to add the font to my application(Apart from the font specified in the API). Thanks in advance lakshman

  • Interface with the most adat opti i/o's

    Hi, I currently use RME's Raydat which has 32 adat i/o's. I thought of using two raydats via aggregate device, but aggregate device has never worked solidly for me. Does anyone know of a single interface offering more than 32? Is stacking Motu 2408's