home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************\
- * *
- * DateEx.js -- A subclass of the Date object that adds more string *
- * convertion routines. *
- * *
- * Parameters: The DateEx class takes the same parameters as the Date class. *
- * *
- * This contains a class definition for DateEx(), which is a subclass of the *
- * Date() class. There are several methods defined for DateEx(): *
- * *
- * getSDate() No Parameters *
- * Returns the date as a character *
- * string in the format: *
- * July 21, 1996. *
- * *
- * getSDay() No parameters *
- * Returns the character name for the *
- * day of the week, such as Monday. *
- * *
- * getSMonth() No parameters *
- * Returns the character name for the *
- * month, such as September. *
- * *
- * getSTime() 2 logical parameters (all optional) *
- * <lSeconds> - true to include seconds *
- * <lTwelve) - true to return 12 hour time *
- * Returns the time as a character *
- * string in one of these formats: *
- * () 14:23 *
- * (true) 14:23:01 *
- * (false,true) 2:23pm *
- * (true,true) 2:23:01pm *
- * *
- * getSTimezone() No parameters *
- * Returns the timezone name. *
- * *
- * To load this function library in IntraBuilder, use a command like this: *
- * *
- * _sys.scripts.load(_sys.env.home() + "apps\\shared\\dateex.js"); *
- * *
- * Updated 8/18/96 by IntraBuilder Samples Group *
- * $Revision: 1.3 $ *
- * *
- * Copyright (c) 1996, Borland International, Inc. All rights reserved. *
- * *
- \****************************************************************************/
-
- class DateEx (timeVal) extends Date {
- if (DateEx.arguments.length == 1)
- this.setTime(new Date(timeVal).getTime());
- else
- this.setTime(new Date().getTime());
-
- function getSDate() {
- var sdate = this.getSMonth();
- sdate = sdate + " " + this.getDate();
- sdate = sdate + ", " + (1900 + this.getYear());
- return (sdate);
- }
-
- function getSDay() {
- var day = this.getDay();
- var sday = "";
- switch (day) {
- case 0:
- sday = "Sunday";
- break;
- case 1:
- sday = "Monday";
- break;
- case 2:
- sday = "Tuesday";
- break;
- case 3:
- sday = "Wednesday";
- break;
- case 4:
- sday = "Thursday";
- break;
- case 5:
- sday = "Friday";
- break;
- case 6:
- sday = "Saturday";
- }
- return (sday);
- }
-
- function getSMonth() {
- var month = this.getMonth();
- var smonth = "";
-
- switch (month) {
- case 0:
- smonth = "January";
- break;
- case 1:
- smonth = "February";
- break;
- case 2:
- smonth = "March";
- break;
- case 3:
- smonth = "April";
- break;
- case 4:
- smonth = "May";
- break;
- case 5:
- smonth = "June";
- break;
- case 6:
- smonth = "July";
- break;
- case 7:
- smonth = "August";
- break;
- case 8:
- smonth = "September";
- break;
- case 9:
- smonth = "October";
- break;
- case 10:
- smonth = "November";
- break;
- case 11:
- smonth = "December";
- }
- return (smonth);
- }
-
- function getSTime( seconds, twelve ) {
- var stime = "";
- var am = true;
-
- // first build the hours
- if (twelve) {
- var hours = this.getHours();
- if (hours == 0) {
- stime = "12";
- am = true;
- }
- else if (hours < 12) {
- stime = "" + hours;
- am = true;
- }
- else if (hours == 12) {
- stime = "12";
- am = false;
- }
- else {
- stime = "" + (hours-12);
- am = false;
- }
- }
- else {
- stime = "" + this.getHours();
- }
-
- // then build the minutes
- stime += ":" + (this.getMinutes()<10?"0":"") + this.getMinutes();
-
- // build seconds only if requested
- if (seconds) {
- stime += ":" + (this.getSeconds()<10?"0":"") + this.getSeconds();
- }
-
- // add am/pm string if requested
- if (twelve) {
- stime += (am ? "am" : "pm");
- }
- return (stime);
- }
-
- function getSTimezone() {
- var offset = new Date("1/1/96").getTimezoneOffset();
- var stimezone = "";
-
- if ( offset <= -720 ) {
- stimezone = "Eniwetok";
- }
- else if (offset <= -660 ) {
- stimezone = "Samoa";
- }
- else if (offset <= -600 ) {
- stimezone = "Hawaii";
- }
- else if (offset <= -540 ) {
- stimezone = "Alaska";
- }
- else if (offset <= -480 ) {
- stimezone = "Pacific";
- }
- else if (offset <= -420 ) {
- stimezone = "Mountain";
- }
- else if (offset <= -360 ) {
- stimezone = "Central";
- }
- else if (offset <= -300 ) {
- stimezone = "Eastern";
- }
- else if (offset <= -240 ) {
- stimezone = "Atlantic";
- }
- else if (offset <= -210 ) {
- stimezone = "Newfoundland";
- }
- else if (offset <= -180 ) {
- stimezone = "Brasilia";
- }
- else if (offset <= -120 ) {
- stimezone = "Mid Atlantic";
- }
- else if (offset <= -60 ) {
- stimezone = "Azores";
- }
- else if (offset <= 0 ) {
- stimezone = "Greenwich Mean";
- }
- else if (offset <= 60 ) {
- stimezone = "Paris";
- }
- else if (offset <= 120 ) {
- stimezone = "Eastern Europe";
- }
- else if (offset <= 180 ) {
- stimezone = "Moscow";
- }
- else if (offset <= 210 ) {
- stimezone = "Tehran";
- }
- else if (offset <= 240 ) {
- stimezone = "Volgograd";
- }
- else if (offset <= 270 ) {
- stimezone = "Kabul";
- }
- else if (offset <= 300 ) {
- stimezone = "Islamabad";
- }
- else if (offset <= 330 ) {
- stimezone = "Bombay";
- }
- else if (offset <= 360 ) {
- stimezone = "Dhaka";
- }
- else if (offset <= 420 ) {
- stimezone = "Jakarta";
- }
- else if (offset <= 480 ) {
- stimezone = "Hong Kong";
- }
- else if (offset <= 540 ) {
- stimezone = "Tokyo";
- }
- else if (offset <= 570 ) {
- stimezone = "Adelaide";
- }
- else if (offset <= 600 ) {
- stimezone = "Sydney";
- }
- else if (offset <= 660 ) {
- stimezone = "Magadan";
- }
- else if (offset <= 720 ) {
- stimezone = "Wellington";
- }
- return (stimezone + " Time");
- }
-
- }