Problem with leap years in Calendar demo

I've just looked at the Calendar demo component:
http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/samplecomps/calendar.html
There is a little bug : it doesn't seem to manage leap years.
Go to february 2008, and you won't the the 29th of February 2008 in the calendar.
Please try to correct this bug quickly. It is a bad idea to let people get source code with bugs as a a demo.
Thanks
Thibaut REGNIER
See TastePhone, my Open Source app made whith Java Studio Creator:
http://www.club-java.com/TastePhone/J2ME/MIDP_mobile.jsp

The Calendar Component does take account of the leap year.
If you look at the code, it has
if ((month == FEBRUARY) && (isLeapYear(year))) numCells++;Not sure what went wrong. I'll take a look at it.
- Winston

Similar Messages

  • I have a 2010 mac book pro and track pad is not working well, is there a problem with that year?

    I have a 2010 mac book pro and track pad is not working well, is there a problem with that year. I heard that the 2011's had track pad trouble.

    All recent versions of Mac OS X use bash, so avoiding Mavericks won't help you with that problem (which isn't a problem for most users).
    iWeb is another matter. My advise: migrate your website to Wordpress first and start thinking about upgrades later.

  • How to do a date validation with leap years

    I'm doing a date validation program in my Java class, and well it's pretty hard (for me that is). I have to be able to type in a date, have it say whether it's a leap year or not, and print out the number of days in the month. It seems pretty straight forward, but I get confused on trying to do the 'if else' statements and even the simplest things like getting the day prompting to work. >< The years I'm doing only goes through 1000 to 1999, so that's why those numbers are there. The program isn't complete, so if anyone could help show me what I'm doing wrong in the areas I'm working on then I'd appreciate it...and I'm still kind of in the basics of Java so if you do hint me with some code then I'd appreciate it if it was stuff that's not too advanced so yea.
    // Dates.java
    // Determine whether a 2nd-millenium date entered by the user
    // is valid
    import java.util.Scanner;
    public class Dates
    public static void main(String[] args)
    int month, day, year; //date read in from user
    int daysInMonth; //number of days in month read in
    boolean monthValid, yearValid, dayValid; //true if input from user is valid
    boolean leapYear; //true if user's year is a leap year
    Scanner scan = new Scanner(System.in);
    //Get integer month, day, and year from user
    System.out.print("Type in the month: " );
              month = scan.nextInt();
    System.out.print("Type in the day: " );
              day = scan.nextInt();
    System.out.print("Type in the year: " );
              year = scan.nextInt();
    //Check to see if month is valid
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;
    //Check to see if year is valid
    if (year >= 1000)
    year = year;
    else
    if (year <= 1999)
    year = year;
    else;
    //Determine whether it's a leap year
    //Determine number of days in month
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
         System.out.println (Number of days in month is 31);
         else (year == 4 || 6 || 9 || 11)
         System.out.println (Number of days in month is 30);
    //User number of days in month to check to see if day is valid
    //Determine whether date is valid and print appropriate message
    // Dates.java
    // Determine whether a 2nd-millenium date entered by the user
    // is valid
    import java.util.Scanner;
    public class Dates
    public static void main(String[] args)
    int month, day, year; //date read in from user
    int daysInMonth; //number of days in month read in
    boolean monthValid, yearValid, dayValid; //true if input from user is valid
    boolean leapYear; //true if user's year is a leap year
    Scanner scan = new Scanner(System.in);
    //Get integer month, day, and year from user
    System.out.print("Type in the month: " );
              month = scan.nextInt();
    System.out.print("Type in the day: " );
              day = scan.nextInt();
    System.out.print("Type in the year: " );
              year = scan.nextInt();
    //Check to see if month is valid
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;
    //Check to see if year is valid
    if (year >= 1000)
    year = year;
    else
    if (year <= 1999)
    year = year;
    else;
    //Determine whether it's a leap year
    //Determine number of days in month
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
         System.out.println (Number of days in month is 31);
         else (year == 4 || 6 || 9 || 11)
         System.out.println (Number of days in month is 30);
    //User number of days in month to check to see if day is valid
    //Determine whether date is valid and print appropriate message
    }

    Here are some helpfull hints for you:
    1. Your code is really hard to read, there are two main reasons for this. First, your indentation sucks. Second, you seem to be fascinated with saving two (ok four if you count the shift key) keypresses to avoid using { and }.
    2. Not using the brackets (you know { and } which you like to avoid) also is causing your code to do some stuff you don't realize or want to happen, or at least it would be if your code compiled.
    3. If statements require arguements, "year == 1" is an arguement, "3" is not an arguement. Each operator like the or operator ("||") is essentially a new if and requires a complete arguement. So the following code peice:
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)Literally translates to if year equals 1 or if 3 or if 5 or if 7 or if 8 or if 10 or if 12. Doesn't make much sense in english, and it doesn't make much sense in Java either.
    4. I am pretty sure "year" is not the variable you want in the code snippet above (the one used in hint 3), especially considering years 1, 3, 5, 7, 8, 10, and 12 are not between 1000 and 1999. You need to be really carefull not make these kind of mistakes when coding, because they are by far the hardest to track down and fix later since they don't really throw up any flags or anything at compile or run time. Take your time and think thuroughly about each line of code while coding it, it will save you tons of time in the long run.
    5. What exactly do you expect statements like "month = month;" to do? That translates as make month equal to month. Do you go to the bank and say " I have exactly $3.56 in my pocket, so I would like to deposite all $3.56 and then withdraw $3.56 and put it back in my pocket"? How do you think the teller would look at you? Teller would probably do it, but the teller would feel like he/she wasted time with you and that you are not really right in the head. Java feels the same way when you make it do the same thing, and you love to do it.
    6. Code like the following is all wrong, and for more reasons than pointed out in hint 5.
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;Let's say someone put 13 in as the month. It passes the first check because 13 is greater than or equal to 1. so month which is 13, now gets set to 13 (gee that was effective). Now we hit the else and things get confusing because you didn't use brackets or proper indentation (hint 1) so we don't know what your real intent was. Did you mean else do nothing, and the next if statement is then executed, or did you mean to just run the next if statement if the else condition was met? Fortunatly it doesn't matter here because the next if statement is failed anyways since 13 is not less than or equal to 12.
    So, we leave this code with month ebing 13, wait when did we add a 13th month to the calendar? Are you using the Jewish calendar? Could be, except even if I put 1234567 as the month your code would except it as valid, and I know no calendar with that many months. Try writing this in english first and translating it to jave, like i would probably say "if the month is greater than or equal to 1 and less than or equal to 12 then the month is valid." Course now what do you do if it is invalid? Hmm, maybe I would actually say "while the month is less than 1 or greater than 12 ask the user for the month" until they get it right.
    There are a few other problems, but most of them are probably things you haven't learned yet, and they are not show stoppers so we will let them fly. You already have a lot of work to do to make this better. But I do have one more really really big usefull hint for you:
    Never, ever, under any circumstances, should you ever ask in any way or even hint at asking for someone else to provide code solutions to your problems. So "so if you do hint me with some code then I'd appreciate it if it was stuff that's not too advanced " was a very bad thing to do, but fortunatly for you you followed it with proof you were trying to write the code yourself. Had the code you provided not been so full of problems it was obvious a beginner wrote it, you would probably have gotten much less cordial responses. I would seriously consider avoiding any implication of wanting code, at least until you become a regular poster here and people know you are not just looking to get your homework done for you.
    Hope some of this helps.
    JSG

  • Problem with af:selectInputDate (no calendar popup)

    Hi All,
    I have a problem with the af:selectInputDate component and the calendar popup when using a custom converter. My converter converts the date in a way, that it always has a four digit year depending on the short date format and the corresponding locale, e.g. 01/18/2007 instead of 01/18/07 for en-us. It looks like when I am using my converter with the component in the following way some javascript is not generated by the af:selectInputDate which results in an javascript error when clicking on the popup button:
    <h:panelGroup>
    <af:selectInputDate id="idPatientBirthDate" columns="12" simple="true" value="#{PatientDetails.patient.birthDate}">
    <f:converter converterId="BirthdateConverter" />
    </af:selectInputDate>
    <h:message for="idPatientBirthDate" errorClass="errorMessageStyle"></h:message>     
    </h:panelGroup>
    The following javascript is not generated using the above jsf:
    <script>
    if(window['_dfs'] == (void 0)){var _dfs=new Object();}_dfs["_id43:general:idPatientBirthDate"]='M/d/yyyy';function __id43Validator(){return true;}
    </script>
    I am using version 10.1.3.0.4 of ADF faces.
    My BirthdateConverter is a standard converter that implements the Converter interface and is not doing any magical. It works perfectly for other components. An interesting fact is, that the above javascript gets generated when I am using no converter at all or the standard date/time converters like f:convertDateTime provided by the RI. However, these don't provide the functionality I need.
    I have the bad feeling, that I am missing something. Does anyone else ran across this problem?
    Thanks,
    Herbert

    Frank,
    Thank you for your answer. I'm not using ADF BC, so is there a possible workaround? My model provides a standard java.util.Date. My converter looks like:
    public class BirthdateConverter implements Converter {
      public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String sDate) {
        Locale locale = facesContext.getCurrentInstance().getExternalContext().getRequestLocale();
        String pattern = AppUtil.getFourDigitYearPattern(DateFormat.SHORT);
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale);
        java.util.Date d = sdf.parse(sDate);
        // converter logic
        return d;
      public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object object) {
        if (object == null)
          return null;
        if (!(object instanceof Date))
          return object.toString();
        Locale locale = facesContext.getCurrentInstance().getExternalContext().getRequestLocale();
        String pattern = AppUtil.getFourDigitYearPattern(DateFormat.SHORT);
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale);
        return sdf.format((java.util.Date)object);
    }AppUtil.getFourDigitYearPattern(DateFormat.SHORT) provides a date pattern, e.g. "M/d/yyyy" for locale en-us. In the above code I did not include try-catch blocks to make it more readable.
    Herbert
    Message was edited by:
    user575859

  • Handling weeks in Planning with leap years

    How are people handling weeks-based forecasting in Planning?
    I have a Planning app that has 53 time periods with an extra week in August to handle the leap year (thus the 53). There are dynamically calculated months, quarters, and the always-loved YearTotal in Time as well.
    This works fine in a leap year, but is kludgy otherwise as it includes an additional month in August – this skews form spreads.
    And it gets even uglier when calculating/data viewing year over year forms as the start week for September should vary across leap and non-leap years.
    It occurred to me that I could create a custom dimension called “Weeks” with all 53 weeks and then use a nested dimension strategy that combined a 12 months Time dimension and the relevant weeks (some hard coding there on forms). I could then use the form column/row suppression to show/hide weeks by month.
    The upsides:
    1)     Smaller block size, as Weeks would go sparse and Time would get reduced from 53 to 12 members.
    2)     True week/month relationships in reporting/forms through prepopulated data and suppression.
    3)     True 4-4-5 spreads to months (although an algorithm to spread to the separate Weeks would have to exist, but that is irrespecitive of the 4-4-5 spread). NB -- 445, etc., concepts don't work in a Planning app with weeks.
    I see a few downsides to this:
    1)     The possibility of entering data by week into the wrong month <-- Form construction could mitigate this.
    2)     Block creation issues in calcs as there is another sparse dimension to take care of.
    3)     Many more blocks <-- How about 53 of them?
    Any thoughts on this approach? I’m not scared of the calcs although I appreciate it’s a little more complicated. I don’t think it breaks the Scenario dimension’s opening/closing of periods. I guess I’m trying to see if there are any hidden issues with this approach and if anyone has figured out a better way to do this.
    Thanks,
    Cameron Lackpour

    The Calendar Component does take account of the leap year.
    If you look at the code, it has
    if ((month == FEBRUARY) && (isLeapYear(year))) numCells++;Not sure what went wrong. I'll take a look at it.
    - Winston

  • Problems with Yahoo Mail and Calendar on MacBook air.  Very slow performance.  Any ideas?

    I have a macbook air running Apple's latest OS. My system is up-to-date.  Over the last few weeks, I have had a very difficult time accessing my yahoo mail and calendar.  I can access other sites, thus I know my connection is solid.  The problem seems to be limited to Yahoo.  I can access my yahoo account on my husband's PC without any issues.  To be specific, here are the symptoms of my problem.  When I try to open my yahoo mail on the Mac, I get the spinning wheel for several minutes.  I view my yahoo calendar through ical.  Yahoo is not connecting with ical, thus my calendar is empty.  I verified my settings and they are correct.  Also, sometimes after trying and retrying the calendar will connect.  I checked the web and did not find any info about this problem.  I appreciate your assistance.

    I have been having the same issue. I can't figure it out. I have tried setting this up my yahoo calendar on my phone and my computer and my iPhone with no luck. It's definitely a Yahoo Problem. At this point I have become enemy to Yahoo Calendar.

  • Problem with Leap if I use Aegis Client on winCE4.2

    Hello
    With Cisco PC-Card is no problem to authenticate with leap. But I am struggeling with the meetinghouse aegis client installed on Symbol MC3000 with windwos CE 4.2.
    I tried with dyn. wep and ktip, but both failed with the aegis client. There is absolutely no entry in the cisco ACS.
    Any input is very welcome
    Oliver

    Yes, you are right. I found it out too.
    TKIP with LEAP on windows CE 4.20 is working proper only with aegis client 2.1.4 from meetinghouse.
    best regards
    Oliver

  • Firefox is having problems with google and google calendars

    Two things: can't keep two separate google accounts functioning, one being their calendar used by a client to which we have access (client A), and the other a gmail inbox (client B).
    The two accounts are unrelated but accessed from the same computer. When trying to refresh after appt setting for client A, google defaults to client B's calendar and logs me out of their gmail account.
    Second hassle, incoming messages to the gmail inbox activates the scroll bar and takes me to the bottom of whatever page I am viewing on the net, or if I'm typing an email hangs the machine so I can't use the keyboard or swap between tabs.
    I also have trouble with plugins so wonder where the problem lies?

    Is it a safe assumption that website is your's? <br />
    What difference does it make which browser '''''you''''' use? Isn't your website for client's or potential clients?
    That said, I don't have a problem with that web page on Firefox 2.0.0.20, 3.0.19, 3.5.16, 3.6.13, or the 4.0b9 nightly - it looks the same as in IE8 on 32-bit WinXP SP3, with an AMD 64-bit processor.
    The problem shown in your screenshot is with your own Firefox installation. It's like all the "styling" is turned off.
    ''''' "I infer Firefox needs a 64 bit version." ''''' <br />
    What good is a 64-bit browser without 64-bit plugins? <br />
    Adobe still hasn't released a 64-bit version of Flash, although they do have a "preview" version available. <br />
    http://kb2.adobe.com/cps/000/6b3af6c9.html
    ''BTW, Mozilla does have a Windows 64-bit version of the Firefox 4.0 betas that is being tested now, but it is not going to be released in Jan / Feb when Firefox 4.0 is released. It will probably be released later in 2011 with one of the 4.# versions, I suspect right after Adobe has a 64-bit Flash release version.''

  • Problem with Fiscal Year/Period

    Hi Expert,
    I am facing an issue with Fiscal year/per in my query. User is running the report on web. When he enters Fiscal year and period in selection screen, the report fetches correct data, however if I go to the information tab, there the value of the fiscal year/per is wrong. e.g. The user enters 010 2007. The report fetches 010.2007 data only but in the information tab, the value of the variable is shown 010.2008
    Please help me in identifying the issue.

    There might be one more variable in the query which is not of type ready for input.
    Fiscal year/per  can be the name of two variables in the query.
    Check in the query if you have one more variable.
    Hope this helps.

  • TWO problems with iphone 3G S Calendar

    First of all, my calendar always alerts me 10 minutes before an event regardless of whether I asked it to or not. I can select 'none' and hit done, but when I go back to the event, the alert is set to go off ten minutes before (it appears to change, but then changes back on it's own). This means when I've created an all-day event, it's waking me up at 11:50 at night to tell me my phone bill is due... So because of this I downloaded another calendar app and tried to delete all the events from the iphone calendar... and here comes the second problem. In the same strange way the alerts keep setting themselves, the events I delete reappear! I simply CANNOT delete any event I ever set to occur monthly or yearly. It seems to understand when I want to delete an one-off event (those haven't magically reappeared... yet) but not any others. I even tried changing the event to NOT be a recurring one before attempting to delete it, and that still didn't work. I think it's important to say that it seems to disappear, but will reappear after you've clicked into something else and gone back. I am definitely hitting 'done' before leaving the calendar, too, so it's not because I'm not saving it. It's really frustrating to be woken up in the middle of the night... It's the only bad experience I've had with this phone! Help!

    my phone actually does 'sync' it just never completes the job. each time I go throught the process some things are actually done as for as changes I am trying to implement but others are not. the acytual syunc process just never stops, like I said before it will say 'sync in progress' for literally days without completing.

  • Sync Problem with Outlook and Blackberry Calendars

    I am hoping someone has an "easy" solution to this problem.
    I am using Desktop Sync (BIS) and synching it to my work Outlook 2007 mailbox.
    Normally my calendar entries should sync to the Blackberry calendar associated with my work email address. Somehow, over the course of the past several days, some of my syncing was occuring with the the VZW Blackberry calendar. I didn't catch the problem in time and now I have work calendar entries correctly listed on my Blackberry, but in two different calendars.
    I have since lost some of those entries originally created in Outlook. They are on the Blackberry, but on the wrong Calendar. When I sync with Desktop, the work entries on the VZW Calendar are not getting over to Outlook.
    So the question is - is there a way to "move" the entries in one BB calendar, over to the other calendar? Thanks.

    I would love to know the answer to this problem as well.  I had the same problem even when I downgraded back to 5.0.  It always worked fine before.  Very Frustrating.  To get around it clearing out all the settings on my handheld.  I just have to click no every time it asks if I want to clear all databases on the phone before sync.  It still syncs but doesn't change my settings.  Annoying but works until they get this aggravation fixed. 

  • Problem with New Year & My Clock--shows wrong year

    Hi, anyone else having this issue? I just checked my world clock on my iphone, as I have contacts all over the world. It all looks right except for Japan, which of course is many hours ahead of me in the EST of the USA. For London, Paris, NYC, etc. the time is right but now (at 11:26am) for Tokyo, Japan the clock says "1:27AM on 07/12/31".
    Since Japan is already in 2008 as I'm writing the message It seems related to the difference in years. I hope this will correct itself when we reach 2008.

    I have Sydney, Australia in my world clock, and i have the same problem. I hope it doesn't do this when it becomes the new year in Chicago.
    When I first got my iphone, i called somebody and in my recent calls it said "Name 12/26/31" which i thought was weird... and every time i called anybody else the one with the funky year would stay on top.. then i cleared my recent calls and it was all back to normal... Maybe this has to do with the weird world clock dates....

  • I'm having problems with syncing my iphone calendar to my ipad, but not the other way around

    My iPhone 5 will not sync with my iPad calendar.  If I make any changes or add an appointment on my iPhone it will not sync to either iCloud or my iPad, however if I add or change an appointment on my iPad or iCloud it will update my iPhone calendar.  I've read where other's are having the same problems but haven't read anyone's post of where a solution has helped.  Anyone??

    There is no  8/9 pin to 30-pin to adopters that support audio. There are such adopters but they only support charging and syncing, not audio
    http://www.guuds.com/product/iP5-9020__Lightning-8-Pin-Female-to-30-Pin-Male-Ada pter-for-iPhone-4S-iPad-3-iPod-Touch-4-Black.html
    says
    Notice: this converter adapter can not support any audio and video product
    Message was edited by: lllaass got mixed up

  • SQL date query problem with century/ year

    We have an oracle database with about 6 million records. There is a date field called Entered Date that ranges from 1985 to the present.
    The majority of these records were entered prior to Jan 1 2000.
    If I run a query like
    select count(*) from (tablename) where entered_date < '01-JAN-00' I get 0
    if I do
    select count(*) from (tablename) where entered_date < '31-DEC-99' I get 0
    BUT IF I DO
    select count(*) from (tablename) where entered_date < '01-JAN-00' I get 6 million records
    or
    select count(*) from TREASURY.ctrc where entrydate > '31-DEC-99' I get 6 million records
    I've tried the same queries using 4 digit years but get the same results; it thinks that 2000 is the less than 1999
    How do I get around this?
    thanks

    Hi,
    975204 wrote:
    there are 6 million records on the table
    about two thirds have a date prior to Jan 1 , 2000How do you know that? From knowledge of the application, you may know that two thirds of them are supposed to have dates prior to 2000, but if
    SELECT  COUNT (*)
    FROM      TABLE_NAME
    WHERE      ENTRYDATE < TO_DATE ( '01-JAN-2000'
                           , 'DD-MON-YYYY'
    ;returns 0, that's pretty strong proof that none of them actually do.
    When I look at the dates , they display as 31-DEC-86Another example of why using 2-digit years is such a bad idea.
    I cant actually provide dump of this clients confidential dataSeriously; you can't provide one DUMP output? You've already said that it displays as 31-DEC-86, so even if the fact that 1 entry in the 6-million row table was done on December 31, 1986 was such a big secret, it's already out, and you won't be causing any more harm by showing the DUMP results.
    I ran the query with the same format as the date ie
    SELECT COUNT(*) FROM TREASURY.CTRC WHERE ENTRYDATE < TO_DATE ( '31-DEC-99'
    , 'DD-MON-YY'
    but same results
    if the column is defined as a DATE type, does Oracle make a distinction based on how the data displays, meaning does it think that 31-DEC-86 is different than 31-DEC-1986?No, all DATE columns have the same format. A DATE may be displayed one way of the other, but it is stored as neither.
    Do I need to convert all the data to a 4 digit year? You should always display dates with a 4-digit year.
    Run an update query that says if year >= 80 and <= 99 add 19 in front of the year, else add 20 in front of the yearLet's find out exactly what the problem is, first.
    Did you see Ascheffer's message? ^1^ It was dated just a couple of minutes before your last message, so you might not have noticed it. Run it to see what the actual 4-digit years are.
    If it shows, for example, that there are a lot of entrydates in the years 2080 to 2099, and you decide that all of those really should be 100 years earlier, then use ADD_MONTHS to correct them:
    UPDATE     table_name
    SET     entrydate = ADD_MONTHS ( entrydate
                               , -100 * 12
    WHERE   entrydate >= TO_DATE ( '01-JAN-2080'
                             , 'DD-MON-YYYY'
    AND     entrydate <  TO_DATE ( '01-JAN-2100'
                             , 'DD-MON-YYYY'
    ;Edited by: Frank Kulash on Mar 15, 2013 6:09 PM
    ^1^ Obviously, you did see Ascheffer's message; I was still typing the message above when you posted another one.

  • Problem with exchange syncing and calendar

    Hi,
    I found a bug on the iphone (2.0.2)
    When I create a rendez-vous in calendar and I add a note on several lines
    example :
    Mr Doe
    Phone : 00000000
    This contact won't synchronize with the exchange server (mail2web), if I create the same appointment on my mac (entourage) it will sync normally.
    If I create the same appointment with calendar (on the iphone) and do'nt write the note on several lines, example :
    Mr Doe, Phone : 000000
    It will sync normally.
    Someone else also has this problem ?
    Message was edited by: bobby001

    I also experianced this problem after an upgrade to Mountain Lion.
    I think it has to do with the fact that in Lion the account settings were managed from iCal, and now they are managed by the OS?
    Anyway I finally solved it by:
    Open Calendar (formerly iCal).
    Go to the Calendar menu and select Preferences.
    Select the Accounts tab.
    Remove the Exchange server account which is giving you the error messages.  This calendar will be removed from the Calendar app.
    Go to System Preferences and click on the "Mail, Contacts & Calendars" pane, find your Exchange server account, and check the "Calendars & Reminders" option to re-enable your calendar.
    Your Calendar should now sync properly.
    I had to do this for all of the accounts I had set up in Calander, and haven't had any problems since.

Maybe you are looking for