home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / progs / ite / ite10d1.exe / DATA.Z / DATEEX.JS < prev    next >
Encoding:
Text File  |  1996-09-07  |  8.8 KB  |  273 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. * DateEx.js  --  A subclass of the Date object that adds more string         *
  4. *                convertion routines.                                        *
  5. *                                                                            *
  6. * Parameters:  The DateEx class takes the same parameters as the Date class. *
  7. *                                                                            *
  8. * This contains a class definition for DateEx(), which is a subclass of the  *
  9. * Date() class. There are several methods defined for DateEx():              *
  10. *                                                                            *
  11. *    getSDate()     No Parameters                                            *
  12. *                   Returns the date as a character                          *
  13. *                   string in the format:                                    *
  14. *                   July 21, 1996.                                           *
  15. *                                                                            *
  16. *    getSDay()      No parameters                                            *
  17. *                   Returns the character name for the                       *
  18. *                   day of the week, such as Monday.                         *
  19. *                                                                            *
  20. *    getSMonth()    No parameters                                            *
  21. *                   Returns the character name for the                       *
  22. *                   month, such as September.                                *
  23. *                                                                            *
  24. *    getSTime()     2 logical parameters (all optional)                      *
  25. *                    <lSeconds> - true to include seconds                    *
  26. *                    <lTwelve)  - true to return 12 hour time                *
  27. *                   Returns the time as a character                          *
  28. *                   string in one of these formats:                          *
  29. *                     ()             14:23                                   *
  30. *                     (true)         14:23:01                                *
  31. *                     (false,true)   2:23pm                                  *
  32. *                     (true,true)    2:23:01pm                               *
  33. *                                                                            *
  34. *   getSTimezone()  No parameters                                            *
  35. *                   Returns the timezone name.                               *
  36. *                                                                            *
  37. * To load this function library in IntraBuilder, use a command like this:    *
  38. *                                                                            *
  39. *     _sys.scripts.load(_sys.env.home() + "apps\\shared\\dateex.js");        *
  40. *                                                                            *
  41. * Updated 8/18/96 by IntraBuilder Samples Group                              *
  42. * $Revision:   1.3  $                                                        *
  43. *                                                                            *
  44. * Copyright (c) 1996, Borland International, Inc. All rights reserved.       *
  45. *                                                                            *
  46. \****************************************************************************/
  47.  
  48. class DateEx (timeVal) extends Date {
  49.    if (DateEx.arguments.length == 1)
  50.       this.setTime(new Date(timeVal).getTime());
  51.    else
  52.       this.setTime(new Date().getTime());
  53.  
  54.    function getSDate() {
  55.       var sdate = this.getSMonth();
  56.       sdate = sdate + " " + this.getDate();
  57.       sdate = sdate + ", " + (1900 + this.getYear());
  58.       return (sdate);
  59.    }
  60.  
  61.    function getSDay() {
  62.       var day = this.getDay();
  63.       var sday = "";
  64.       switch (day) {
  65.       case 0:
  66.          sday = "Sunday";
  67.          break;
  68.       case 1:
  69.          sday = "Monday";
  70.          break;
  71.       case 2:
  72.          sday = "Tuesday";
  73.          break;
  74.       case 3:
  75.          sday = "Wednesday";
  76.          break;
  77.       case 4:
  78.          sday = "Thursday";
  79.          break;
  80.       case 5:
  81.          sday = "Friday";
  82.          break;
  83.       case 6:
  84.          sday = "Saturday";
  85.       }
  86.       return (sday);        
  87.    }
  88.  
  89.    function getSMonth() {
  90.       var month = this.getMonth();
  91.       var smonth = "";
  92.  
  93.       switch (month) {
  94.       case 0:
  95.          smonth = "January";
  96.          break;
  97.       case 1:
  98.          smonth = "February";
  99.          break;
  100.       case 2:
  101.          smonth = "March";
  102.          break;
  103.       case 3:
  104.          smonth = "April";
  105.          break;
  106.       case 4:
  107.          smonth = "May";
  108.          break;
  109.       case 5:
  110.          smonth = "June";
  111.          break;
  112.       case 6:
  113.          smonth = "July";
  114.          break;
  115.       case 7:
  116.          smonth = "August";
  117.          break;
  118.       case 8:
  119.          smonth = "September";
  120.          break;
  121.       case 9:
  122.          smonth = "October";
  123.          break;
  124.       case 10:
  125.          smonth = "November";
  126.          break;
  127.       case 11:
  128.          smonth = "December";
  129.       }
  130.       return (smonth);
  131.    }
  132.  
  133.    function getSTime( seconds, twelve ) {
  134.       var stime = "";
  135.       var am = true;
  136.  
  137.       // first build the hours
  138.       if (twelve) {
  139.          var hours = this.getHours();
  140.          if (hours == 0) {
  141.             stime = "12";
  142.             am = true;
  143.          }
  144.          else if (hours < 12) {
  145.             stime = "" + hours;
  146.             am = true;
  147.          }
  148.          else if (hours == 12) {
  149.             stime = "12";
  150.             am = false;
  151.          }
  152.          else {
  153.             stime = "" + (hours-12);
  154.             am = false;
  155.          }
  156.       }
  157.       else {
  158.          stime = "" + this.getHours();
  159.       }
  160.  
  161.       // then build the minutes
  162.       stime += ":" + (this.getMinutes()<10?"0":"") + this.getMinutes();
  163.  
  164.       // build seconds only if requested
  165.       if (seconds) {
  166.          stime += ":" + (this.getSeconds()<10?"0":"") +  this.getSeconds();
  167.       }
  168.  
  169.       // add am/pm string if requested
  170.       if (twelve) {
  171.          stime += (am ? "am" : "pm");
  172.       }
  173.       return (stime);
  174.    }
  175.  
  176.    function getSTimezone() {
  177.       var offset = new Date("1/1/96").getTimezoneOffset();
  178.       var stimezone = "";
  179.  
  180.       if ( offset <= -720 ) {
  181.          stimezone = "Eniwetok";
  182.       }
  183.       else if (offset <= -660 ) {
  184.          stimezone = "Samoa";
  185.       }
  186.       else if (offset <= -600 ) {
  187.          stimezone = "Hawaii";
  188.       }
  189.       else if (offset <= -540 ) {
  190.          stimezone = "Alaska";
  191.       }
  192.       else if (offset <= -480 ) {
  193.          stimezone = "Pacific";
  194.       }
  195.       else if (offset <= -420 ) {
  196.          stimezone = "Mountain";
  197.       }
  198.       else if (offset <= -360 ) {
  199.          stimezone = "Central";
  200.       }
  201.       else if (offset <= -300 ) {
  202.          stimezone = "Eastern";
  203.       }
  204.       else if (offset <= -240 ) {
  205.          stimezone = "Atlantic";
  206.       }
  207.       else if (offset <= -210 )  {
  208.          stimezone = "Newfoundland";
  209.       }
  210.       else if (offset <= -180 ) {
  211.          stimezone = "Brasilia";
  212.       }
  213.       else if (offset <= -120 ) {
  214.          stimezone = "Mid Atlantic";
  215.       }
  216.       else if (offset <= -60 ) {
  217.          stimezone = "Azores";
  218.       }
  219.       else if (offset <= 0 )    {
  220.          stimezone = "Greenwich Mean";
  221.       }
  222.       else if (offset <= 60 )   {
  223.          stimezone = "Paris";
  224.       }
  225.       else if (offset <= 120 )  {
  226.          stimezone = "Eastern Europe";
  227.       }
  228.       else if (offset <= 180 )  {
  229.          stimezone = "Moscow";
  230.       }
  231.       else if (offset <= 210 ) {
  232.          stimezone = "Tehran";
  233.       }
  234.       else if (offset <= 240 )  {
  235.          stimezone = "Volgograd";
  236.       }
  237.       else if (offset <= 270 ) {
  238.          stimezone = "Kabul";
  239.       }
  240.       else if (offset <= 300 )  {
  241.          stimezone = "Islamabad";
  242.       }
  243.       else if (offset <= 330 ) {
  244.          stimezone = "Bombay";
  245.       }
  246.       else if (offset <= 360 )  {
  247.          stimezone = "Dhaka";
  248.       }
  249.       else if (offset <= 420 )  {
  250.          stimezone = "Jakarta";
  251.       }
  252.       else if (offset <= 480 )  {
  253.          stimezone = "Hong Kong";
  254.       }
  255.       else if (offset <= 540 )  {
  256.          stimezone = "Tokyo";
  257.       }
  258.       else if (offset <= 570 ) {
  259.          stimezone = "Adelaide";
  260.       }
  261.       else if (offset <= 600 )  {
  262.          stimezone = "Sydney";
  263.       }
  264.       else if (offset <= 660 )  {
  265.          stimezone = "Magadan";
  266.       }
  267.       else if (offset <= 720 )  {
  268.          stimezone = "Wellington";
  269.       }
  270.       return (stimezone + " Time");
  271.    }
  272.  
  273. }