home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / Tstamp.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  20.6 KB  |  687 lines

  1. /*
  2.  * @(#Tstamp.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8.  
  9. package symantec.itools.db.awt;
  10. import java.util.*;
  11. import java.awt.*;
  12. import java.sql.Timestamp;
  13.  
  14. /**
  15.  * A Tstamp component is a text field that accepts and displays text in common
  16.  * date/time formats. It parses the text so that the date and time is available
  17.  * numericly as well.
  18.  */
  19. public class Tstamp extends java.awt.TextField{
  20.  
  21.     /**
  22.      * The day of the month.
  23.      */
  24.     protected int day=1;
  25.     /**
  26.      * The month of the year. 0 = January.
  27.      */
  28.     protected int month=0;
  29.     /**
  30.      * The year.
  31.      */
  32.     protected int year=0;
  33.     /**
  34.      * The hour of the day. 13 = 1 PM.
  35.      */
  36.     protected int hour=0;
  37.     /**
  38.      * The minute of the hour.
  39.      */
  40.     protected int minute=0;
  41.     /**
  42.      * The second of the minute.
  43.      */
  44.     protected int second=0;
  45.     /**
  46.      * The nanosecond of the second.
  47.      */
  48.     protected int nanosec=0;
  49.  
  50.     /**
  51.      * The current data display format.
  52.      * @see #getDisplayFormat
  53.      * @see #setDisplayFormat
  54.      */
  55.     protected String m_DisplayFormat="";
  56.     /**
  57.      * The current data entry format.
  58.      * @see #getEntryFormat
  59.      * @see #setEntryFormat
  60.      */
  61.     protected String m_EntryFormat="";
  62.  
  63.     private String DAY[]={"DD","D%","D+","D*","TH"};
  64.     private String MON[]={"MM","M%","M+","M*"};
  65.     private String YEA[]={"YY","Y*"};
  66.     private String HOU[]={"HH","H%","hh","h%","AM"};
  67.     private String MIN[]={"mm","m%"};
  68.     private String SEC[]={"ss","s%"};
  69.     private String NAN[]={"n"};
  70.     private String nMON[]={"Jan.","Feb.","Mar.","Apr.","May ","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."};
  71.     private String NMON[]={"January","February","March","April","May","June","July","August","September",
  72.                            "October","November","December"};
  73.     private String nDAY[]={"Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat."};
  74.     private String NDAY[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
  75.  
  76.     String WAYS[]={"DDMMYY",
  77.                    "D% M% YY",
  78.                    "D%/M%/Y*",
  79.                    "Y*-MM-DD",
  80.                    "DD/MM/YY",
  81.                    "D%-M+-YY",
  82.                    "D% M* Y*",
  83.                    "D+ D% M+ Y*",
  84.                    "D* D% M+ Y*",
  85.                    "M* D% YY",
  86.                    "D* M* D% Y*",
  87.                    "<< M%.D%.YY >>",
  88.                    "Today is D* the D% th of M* Y*",
  89.                    "DD -- MM -- Y*"};
  90. //      CONSTRUCTORS
  91.  
  92.     /**
  93.      * Constructs a Tstamp with the given date.
  94.      * @param date the initial date displayed
  95.      */
  96.     public Tstamp(Date date)
  97.     {
  98.         this.setTstamp(date);
  99.     }
  100.  
  101.     /**
  102.      * Constructs a Tstamp with the given date/time.
  103.      * @param tstamp the initial date and time displayed
  104.      */
  105.     public Tstamp( java.sql.Timestamp tstamp)
  106.     {
  107.         nanosec=tstamp.getNanos();
  108.         this.setTstamp(tstamp);
  109.     }
  110.  
  111.     /**
  112.      * Constructs a default Tstamp.
  113.      */
  114.     public Tstamp()
  115.     {
  116.         this(new Date());
  117.     }
  118.  
  119.     /**
  120.      * Constructs a Tstamp with the given date.
  121.      * @param date the initial date displayed
  122.      */
  123.     public Tstamp(String date)
  124.     {
  125.         this.readDate(date,m_EntryFormat);
  126.     }
  127.  
  128.     /**
  129.      * Constructs a Tstamp with the given date in the given format.
  130.      * @param date the initial date displayed
  131.      * @param format the format the date is in
  132.      */
  133.     public Tstamp(String date,String format)
  134.     {
  135.         this.readDate(date,format);
  136.     }
  137.  
  138.  
  139. //      SETTERS
  140.  
  141.     /**
  142.      * Sets the value to the given date.
  143.      * @param date the new date
  144.      */
  145.     public void setTstamp(String date)
  146.     {
  147.         this.readDate(date,m_EntryFormat);
  148.     }
  149.  
  150.     /**
  151.      * Sets the value to the given date in the given format.
  152.      * @param date the new date
  153.      * @param format the format the date is in
  154.      */
  155.     public void setTstamp(String date, String format)
  156.     {
  157.         this.readDate(date,format);
  158.     }
  159.  
  160.     /**
  161.      * Sets the value to the given date.
  162.      * @param date the new date
  163.      */
  164.     public void setTstamp(Date date)
  165.     {
  166.         day=date.getDate();
  167.         month=date.getMonth();
  168.         year=date.getYear()+1900;
  169.         hour=date.getHours();
  170.         minute=date.getMinutes();
  171.         second=date.getSeconds();
  172.     }
  173.  
  174.     /**
  175.      * Sets the text entry format to the same as the display format.
  176.      * @param date the new date
  177.      */
  178.     public void setinequalout()
  179.     {
  180.         setEntryFormat(getDisplayFormat());
  181.     }
  182.  
  183.     /**
  184.      * Sets the display and input format.
  185.      * @param dispfmt the new display and entry format
  186.      * @see #getDisplayFormat
  187.      */
  188.     public void setDisplayFormat(String dispfmt)
  189.     {
  190.         m_DisplayFormat = dispfmt;
  191.         setinequalout();
  192.     }
  193.  
  194.     /**
  195.      * Sets the entry format.
  196.      * @param entfmt the new entry format
  197.      * @see #getEntryFormat
  198.      */
  199.     public void setEntryFormat(String entfmt)
  200.     {
  201.         m_EntryFormat = entfmt;
  202.     }
  203.  
  204.  
  205. //      GETTERS
  206.  
  207.     /**
  208.      * Returns the current entry format.
  209.      * <p>
  210.      * The entry format defines the order the user must follow to enter a valid
  211.      * timestamp.
  212.      * <p>
  213.      * It is a can either be a String containing  ôMö, öDö ,öYö, öhö,
  214.      * ömö, ösö and ônö or a string using the values for a display format.
  215.      * @see #setEntryFormat
  216.      * @see #getDisplayFormat
  217.      */
  218.     public String getEntryFormat()
  219.     {
  220.         return (m_EntryFormat);
  221.     }
  222.  
  223.     /**
  224.      * Returns the current display format.
  225.      * <p>
  226.      * The display format defines the format in which the date, time, or
  227.      * timestamp values are displayed.
  228.      * Text phrases may also be entered as long as they do not contain any of
  229.      * the valid values.
  230.      * <p>
  231.      * <b>Example:</b><p>
  232.      * ôThe date: D* M* D%TH, Y* H%:mm:ss AM
  233.      * <p>
  234.      * will print
  235.      * <p>
  236.      * ôThe date: Friday October 12th , 1973 2:34:54 PM
  237.      * <p>
  238.      * <b>Note:</b> If the display format values do not include all the data elements
  239.      * provided by the input data, only the values specified in the format will display.
  240.      * <p>
  241.      * For example, a display format of ôMM/DDö displays ô07/01ö even though the
  242.      * complete data may be ô07/01/1996ö.
  243.      * <p>
  244.      * <table>
  245.      * <tr><th>Value</th>
  246.      *     <th>Description</th></tr>
  247.      * <tr><td><code>DD</code></td>
  248.      *     <td>Day - 2 digits  [01-31]</td></tr>
  249.      * <tr><td><code>D%</code></td>
  250.      *     <td>Day - 1 or 2 digits  [1-31]</td></tr>
  251.      * <tr><td><code>D+</code></td>
  252.      *        <td>Day - name of the day abbreviated  [Mon.-Sun.]</td></tr>
  253.      * <tr><td><code>D*</code></td>
  254.      *        <td>Day - name of the day complete  [Monday-Sunday]</td></tr>
  255.      * <tr><td><code>TH</code></td>
  256.      *        <td>puts the [ st-nd-rd-th ] element</td></tr>
  257.      * <tr><td><code>MM</code></td>
  258.      *        <td>Month - 2 digits  [01-12]</td></tr>
  259.      * <tr><td><code>M%</code></td>
  260.      *        <td>Month - 1 to 2 digits  [1-12]</td></tr>
  261.      * <tr><td><code>M+</code></td>
  262.      *        <td>Month - name of the month abbreviated  [Jan.-Dec.]</td></tr>
  263.      * <tr><td><code>M*</code></td>
  264.      *        <td>Month - complete name of the month [January-December]</td></tr>
  265.      * <tr><td><code>YY</code></td>
  266.      *        <td>Year - 2 digits</td></tr>
  267.      * <tr><td><code>Y*</code></td>
  268.      *        <td>Year - 4 digits</td></tr>
  269.      * <tr><td><code>hh</code></td>
  270.      *        <td>Hour - 2 digits</td></tr>
  271.      * <tr><td><code>h%</code></td>
  272.      *        <td>Hour - 1 or 2 digits</td></tr>
  273.      * <tr><td><code>HH</code></td>
  274.      *        <td>Hour - 2 digits, 12 hour clock</td></tr>
  275.      * <tr><td><code>H%</code></td>
  276.      *        <td>Hour - 1 or 2 digits, 12 hour clock</td></tr>
  277.      * <tr><td><code>AM</code></td>
  278.      *        <td>adds a AM or PM symbol</td></tr>
  279.      * <tr><td><code>mm</code></td>
  280.      *        <td>Minutes - 2 digits</td></tr>
  281.      * <tr><td><code>m%</code></td>
  282.      *        <td>Minutes - 1 or 2 digits</td></tr>
  283.      * <tr><td><code>ss</code></td>
  284.      *        <td>Seconds - 2 digits</td></tr>
  285.      * <tr><td><code>s%</code></td>
  286.      *        <td>Seconds - 1 or 2 digits</td></tr>
  287.      * <tr><td><code>n1,n2àn9</code></td>
  288.      *        <td>fractions of a second, number specifies the number of digits.</td></tr>
  289.      * </table>
  290.      * @see #setDisplayFormat
  291.      */
  292.     public String getDisplayFormat()
  293.     {
  294.         return (m_DisplayFormat);
  295.     }
  296.  
  297.     /**
  298.      * Returns the current date/time as a string.
  299.      */
  300.     public String getTstamp()
  301.     {
  302.         return(this.exTstamp(m_DisplayFormat));
  303.     }
  304.  
  305.     /**
  306.      * Returns the current date/time as a string formatted in the specified way.
  307.      * The parameter value specifies one of:
  308.      * <table>
  309.      * <tr><th>Value</th>
  310.      *     <th>Format (see getDisplayFormat)</th></tr>
  311.      * <tr><td><code>0</code></td>
  312.      *     <td><code>DDMMYY</code></td></tr>
  313.      * <tr><td><code>1</code></td>
  314.      *     <td><code>D% M% YY</code></td></tr>
  315.      * <tr><td><code>2</code></td>
  316.      *     <td><code>D%/M%/Y*</code></td></tr>
  317.      * <tr><td><code>3</code></td>
  318.      *     <td><code>Y*-MM-DD</code></td></tr>
  319.      * <tr><td><code>4</code></td>
  320.      *     <td><code>DD/MM/YY</code></td></tr>
  321.      * <tr><td><code>5</code></td>
  322.      *     <td><code>D%-M+-YY</code></td></tr>
  323.      * <tr><td><code>6</code></td>
  324.      *     <td><code>D% M* Y*</code></td></tr>
  325.      * <tr><td><code>7</code></td>
  326.      *     <td><code>D+ D% M+ Y*</code></td></tr>
  327.      * <tr><td><code>8</code></td>
  328.      *     <td><code>D* D% M+ Y*</code></td></tr>
  329.      * <tr><td><code>9</code></td>
  330.      *     <td><code>M* D% YY</code></td></tr>
  331.      * <tr><td><code>10</code></td>
  332.      *     <td><code>D* M* D% Y*</code></td></tr>
  333.      * <tr><td><code>11</code></td>
  334.      *     <td><code><< M%.D%.YY >></code></td></tr>
  335.      * <tr><td><code>12</code></td>
  336.      *     <td><code>Today is D* the D% th of M* Y*</code></td></tr>
  337.      * <tr><td><code>13</code></td>
  338.      *     <td><code>DD -- MM -- Y*</code></td></tr>
  339.      * </table>
  340.      * @param num the way to format the text
  341.      * @see #getDisplayFormat
  342.      */
  343.     public String getTstamp(int num)
  344.     {
  345.         return(this.exTstamp(WAYS[num]));
  346.     }
  347.  
  348.     /**
  349.      * Returns the current date/time as a string formatted in the specified way.
  350.      * @param exform the display format to use
  351.      * @see #getDisplayFormat
  352.      */
  353.     public String getTstamp(String exform)
  354.     {
  355.         return(this.exTstamp(exform));
  356.     }
  357.  
  358.  
  359.     /**
  360.      * Updates the text displayed using the current date/time value and display
  361.      * format.
  362.      * @see #getDisplayFormat
  363.      */
  364.     public void printTstamp()
  365.     {setText(getTstamp(m_DisplayFormat));}
  366.  
  367.     /**
  368.      * Returns the current Tstamp value as a Date.
  369.      * @exception IllegalArgumentException
  370.      * if the date value is out of range (<1970 or >2038)
  371.      */
  372.     public Date getDate()throws IllegalArgumentException
  373.     {
  374.  
  375.         return(new Date(year-1900,month,day,hour,minute,second));
  376.     }
  377.  
  378.     /**
  379.      * Returns the current Tstamp value as a Timestamp.
  380.      * @exception IllegalArgumentException
  381.      * if the date value is out of range (<1970 or >2038)
  382.      */
  383.     public Timestamp getTimestamp()throws IllegalArgumentException
  384.     {
  385.         /*if(1900>year)
  386.         {
  387.             throw new IllegalArgumentException("Year out of range for Timestamp");
  388.         }*/
  389.         return(new Timestamp(year-1900,month,day,hour,minute,second,nanosec));
  390.     }
  391.  
  392.  
  393.  
  394.     /**
  395.      * Internal utility method.
  396.      */
  397.     protected void raiseException(Exception ex)
  398.     {
  399.         System.out.println("Exception class [" + ex.getClass().getName() + "]");
  400.         System.out.println("Exception message [" + ex.getMessage() + "]");
  401.         Thread.dumpStack();
  402.     }
  403.  
  404.     /**
  405.      * Utility method that parses the given date using the specified format.
  406.      * @see #getEntryFormat
  407.      */
  408.     protected void readDate(String date,String format)
  409.     {
  410.         boolean douze=false;
  411.         String tformat="";
  412.         String sub="";
  413.         int value=0;
  414.         int pos=0;
  415.         int act=0;
  416.         int elem=0;
  417.         int count=0;
  418.         char actFormatChar;
  419.         date+=" ";
  420.  
  421.         if(format.length()>2)
  422.         {
  423.             for(int x=0;x<format.length()-1;x++)
  424.             {
  425.                 try{sub=format.substring(x,x+2);
  426.             }
  427.             catch(StringIndexOutOfBoundsException e)
  428.             {
  429.                 raiseException(e);
  430.             }
  431.                 if(sub.equals("DD")||sub.equals("D%")) tformat+="D";
  432.                 else if(sub.equals("MM")||sub.equals("M%")||sub.equals("M+")||sub.equals("M*")) tformat+="M";
  433.                 else if(sub.equals("YY")||sub.equals("Y*")) tformat+="Y";
  434.                 else if(sub.equals("HH")||sub.equals("H%")||sub.equals("hh")||sub.equals("h%")) tformat+="h";
  435.                 else if(sub.equals("m%")||sub.equals("mm")) tformat+="m";
  436.                 else if(sub.equals("s%")||sub.equals("ss")) tformat+="s";
  437.                 else if(sub.charAt(0)=='n')tformat+="n";
  438.             }
  439.         if(tformat.length()>1) format=tformat;
  440.         }
  441.  
  442.     while (elem<format.length() && pos<date.length()){
  443.  
  444.         actFormatChar=format.charAt(elem);
  445.         if(act==0)
  446.         {
  447.             while('0'<=date.charAt(pos) && date.charAt(pos)<='9')
  448.             {
  449.                 value=value*10+date.charAt(pos)-'0';
  450.                 pos++;count++;act=1;
  451.  
  452.             if((actFormatChar=='M' ||actFormatChar=='D'||actFormatChar=='h'
  453.             ||actFormatChar=='m'||actFormatChar=='s')&&(count>1))break;
  454.             if((actFormatChar=='Y')&&(count>3))break;
  455.             }
  456.  
  457.             if(actFormatChar=='n')
  458.             {
  459.                 for(int j=0;j<9-count;j++)
  460.                 {
  461.                     value=value*10;
  462.                 }
  463.             }
  464.  
  465.             if('0'>date.charAt(pos) || date.charAt(pos)>'9')
  466.             {
  467.                 for(int x=0;x<nMON.length;x++)
  468.                 {
  469.                     if(nMON[x].regionMatches(true,0,date,pos,3) && actFormatChar=='M')
  470.                     {
  471.                         value=x+1;
  472.                         pos++;act=1;
  473.                     }
  474.                 }
  475.                 if("PM".regionMatches(true,0,date,pos,2))
  476.                 {
  477.                     douze=true;
  478.                 }
  479.                 pos++;
  480.             }
  481.         }
  482.  
  483.         if(actFormatChar=='M') month=value-1;
  484.         if(actFormatChar=='D') day=value;
  485.         if(actFormatChar=='Y')
  486.         {
  487.             year=value;
  488.             if (year<101)year+=1900;
  489.         }
  490.         if(actFormatChar=='h') hour=value;
  491.         if(actFormatChar=='m') minute=value;
  492.         if(actFormatChar=='s') second=value;
  493.         if(actFormatChar=='n') nanosec=value;
  494.         if (douze && hour<12)hour=hour+12;
  495.  
  496.         if(act!=0){elem++;count=0;act=0;value=0;}
  497.  
  498.         }
  499.         while(pos<date.length())
  500.         {
  501.             if("PM".regionMatches(true,0,date,pos,2))
  502.             {
  503.                 if(hour<12)hour+=12;
  504.             }
  505.             pos++;
  506.         }
  507.         if(month>11) month=11;
  508.         if(month<0) month=0;
  509.         if (month==1 && day>=29)
  510.         {
  511.             if(calculday(29,1,year)==calculday(1,2,year))
  512.             {
  513.                 day=28;
  514.             }
  515.             else
  516.             {
  517.                 day=29;
  518.             }
  519.         }
  520.         else if(day>(moffset[month+1]-moffset[month])) day=(moffset[month+1]-moffset[month]);
  521.         if(day<1) day=1;
  522.         if(hour>23) hour=23;
  523.         if(hour<0) hour=0;
  524.         if(minute>59) minute=59;
  525.         if(minute<0) minute=0;
  526.         if(second>59) second=59;
  527.         if(second<0) second=0;
  528.  
  529.     }
  530.  
  531.      /**
  532.       * Returns the current date/time as a string formatted in the specified way.
  533.       * @see #getDisplayFormat
  534.       */
  535.      protected String exTstamp(String exform)
  536.      {
  537.         int pos=0;
  538.         int actpos=pos;
  539.         int amhour=hour;
  540.         if(hour>11)amhour=hour-12;
  541.         int nansize=0;
  542.         String snan="";
  543.         String output="";
  544.         exform+=" ";
  545.         while (pos<exform.length())
  546.         {
  547.             actpos=pos;
  548.         //DAY[]={"DD","D%","D+","D*","TH"};
  549.             for(int x=0;x<DAY.length;x++)
  550.             {
  551.                 if(DAY[x].regionMatches(0,exform,pos,DAY[x].length()))
  552.                 {
  553.                     pos+=DAY[x].length()-1;
  554.                     if(x==0)
  555.                     {
  556.                         if(day<10)output+="0";
  557.                         output+=Integer.toString(day);
  558.                     }
  559.                     else if(x==1)output+=Integer.toString(day);
  560.                     else if(x==2)output+=nDAY[calculday(day,month,year)];
  561.                     else if(x==3)output+=NDAY[calculday(day,month,year)];
  562.                     else if(x==4)
  563.                     {
  564.                         int lastDigitOfDay=day%10;
  565.                         if(day<10 ||day>13)
  566.                         {
  567.                             if(lastDigitOfDay==1)output+="st";
  568.                             else if(lastDigitOfDay==2)output+="nd";
  569.                             else if(lastDigitOfDay==3)output+="rd";
  570.                             else output+="th";
  571.                         }
  572.                         else output+="th";
  573.                     }
  574.                 }
  575.             }
  576.         //MON[]={"MM","M%","M+","M*"};
  577.             for(int x=0;x<MON.length;x++)
  578.             {
  579.                 if(MON[x].regionMatches(0,exform,pos,MON[x].length()))
  580.                 {
  581.                     pos+=MON[x].length()-1;
  582.                     if(x==0)
  583.                     {
  584.                         if(month+1<10)output+="0";
  585.                         output+=Integer.toString(month+1);
  586.                     }
  587.                     else if(x==1)output+=Integer.toString(month+1);
  588.                     else if(x==2)output+=nMON[month];
  589.                     else if(x==3)output+=NMON[month];
  590.                 }
  591.             }
  592.         //YEA[]={"YY","Y*"};
  593.             for(int x=0;x<YEA.length;x++)
  594.             {
  595.                 if(YEA[x].regionMatches(0,exform,pos,YEA[x].length()))
  596.                 {
  597.                     pos+=YEA[x].length()-1;
  598.                     if(x==0)output+=Integer.toString(year-(year/100)*100);
  599.                     else if(x==1)output+=Integer.toString(year);
  600.                 }
  601.             }
  602.         //HOU[]={"HH","H%","hh","h%","AM"};
  603.             for(int x=0;x<HOU.length;x++)
  604.             {
  605.                 if(HOU[x].regionMatches(0,exform,pos,HOU[x].length()))
  606.                 {
  607.                     pos+=HOU[x].length()-1;
  608.                     if(x==0)
  609.                     {
  610.                         if(amhour<10)output+="0";
  611.                         output+=Integer.toString(amhour);
  612.                     }
  613.                     else if(x==1)output+=Integer.toString(amhour);
  614.                     else if(x==2)
  615.                     {
  616.                         if(hour<10)output+="0";
  617.                         output+=Integer.toString(hour);
  618.                     }
  619.                     else if(x==3)output+=Integer.toString(hour);
  620.                     else if(x==4)
  621.                     {
  622.                         if(hour>11)output+="PM";
  623.                         if(hour<12)output+="AM";
  624.                     }
  625.                 }
  626.             }
  627.         //MIN[]={"mm","m%"};
  628.             for(int x=0;x<MIN.length;x++)
  629.             {
  630.                 if(MIN[x].regionMatches(0,exform,pos,MIN[x].length()))
  631.                 {
  632.                     pos+=MIN[x].length()-1;
  633.                     if(x==0)
  634.                     {
  635.                         if(minute<10)output+="0";
  636.                         output+=Integer.toString(minute);
  637.                     }
  638.                     else if(x==1)output+=Integer.toString(minute);
  639.                 }
  640.             }
  641.         //SEC[]={"ss","s%"};
  642.             for(int x=0;x<SEC.length;x++)
  643.             {
  644.                 if(SEC[x].regionMatches(0,exform,pos,SEC[x].length()))
  645.                 {
  646.                     pos+=SEC[x].length()-1;
  647.                     if(x==0)
  648.                     {
  649.                         if(second<10)output+="0";
  650.                         output+=Integer.toString(second);
  651.                     }
  652.                     else if(x==1)output+=Integer.toString(second);
  653.                 }
  654.             }
  655.         //NAN[]={"n"};
  656.             for(int x=0;x<NAN.length;x++)
  657.             {
  658.                 if(NAN[x].regionMatches(0,exform,pos,NAN[x].length()))
  659.                 {
  660.                     pos+=NAN[x].length();
  661.                     nansize=(int)(exform.charAt(pos)-'0');
  662.                     snan=Integer.toString(nanosec+1000000000);
  663.                     if(x==0)output+=snan.substring(1,nansize+1);
  664.                 }
  665.             }
  666.           if(actpos==pos)output+=exform.charAt(pos);
  667.           pos++;
  668.         }
  669.         return(output);
  670.     }
  671.  
  672.     private int moffset[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
  673.  
  674.     /**
  675.      * Returns the day of the week given the day, month, and year.
  676.      * @see #getDisplayFormat
  677.      */
  678.     public int calculday(int day,int month,int year)
  679.     {
  680.         Date date=new Date(year-1900,month,day);
  681.         return (date.getDay());
  682.     }
  683.  
  684. }
  685.  
  686.  
  687.