home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
ib
/
setups
/
intrabld
/
data.z
/
DATEEX.JS
< prev
next >
Wrap
Text File
|
1996-12-11
|
14KB
|
354 lines
/****************************************************************************\
* *
* DateEx.js -- A subclass of the Date object that adds more string *
* conversion 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: *
* Thursday, September 12, 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:23 PM *
* (true,true) 2:23:01 PM *
* *
* 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 10/31/96 by IntraBuilder Samples Group *
* $Revision: 1.5 $ *
* *
* Copyright (c) 1996, Borland International, Inc. All rights reserved. *
* *
\****************************************************************************/
// from winnls.h
// Copyright (c) 1991-1995, Microsoft Corp. All rights reserved.
/*
* Time Flags for GetTimeFormat
*/
#define TIME_NOMINUTESORSECONDS 0x00000001 /* do not use minutes or seconds */
#define TIME_NOSECONDS 0x00000002 /* do not use seconds */
#define TIME_NOTIMEMARKER 0x00000004 /* do not use time marker */
#define TIME_FORCE24HOURFORMAT 0x00000008 /* always use 24 hour format */
/*
* Date Flags for GetDateFormat
*/
#define DATE_SHORTDATE 0x00000001 /* use short date picture */
#define DATE_LONGDATE 0x00000002 /* use long date picture */
#define DATE_USE_ALT_CALENDAR 0x00000004 /* use alternate calendar (if any) */
/*
* Locale types for GetLocaleInfo
*/
#define LOCALE_SDAYNAME1 0x0000002A /* long name for Monday */
#define LOCALE_SDAYNAME2 0x0000002B /* long name for Tuesday */
#define LOCALE_SDAYNAME3 0x0000002C /* long name for Wednesday */
#define LOCALE_SDAYNAME4 0x0000002D /* long name for Thursday */
#define LOCALE_SDAYNAME5 0x0000002E /* long name for Friday */
#define LOCALE_SDAYNAME6 0x0000002F /* long name for Saturday */
#define LOCALE_SDAYNAME7 0x00000030 /* long name for Sunday */
#define LOCALE_SMONTHNAME1 0x00000038 /* long name for January */
#define LOCALE_SMONTHNAME2 0x00000039 /* long name for February */
#define LOCALE_SMONTHNAME3 0x0000003A /* long name for March */
#define LOCALE_SMONTHNAME4 0x0000003B /* long name for April */
#define LOCALE_SMONTHNAME5 0x0000003C /* long name for May */
#define LOCALE_SMONTHNAME6 0x0000003D /* long name for June */
#define LOCALE_SMONTHNAME7 0x0000003E /* long name for July */
#define LOCALE_SMONTHNAME8 0x0000003F /* long name for August */
#define LOCALE_SMONTHNAME9 0x00000040 /* long name for September */
#define LOCALE_SMONTHNAME10 0x00000041 /* long name for October */
#define LOCALE_SMONTHNAME11 0x00000042 /* long name for November */
#define LOCALE_SMONTHNAME12 0x00000043 /* long name for December */
#define LOCALE_SMONTHNAME13 0x0000100E /* long name for 13th month (if exists) */
class DateEx extends Date {
if (DateEx.arguments.length < 1)
this.setTime(new Date().getTime());
else {
var params = "";
for (var i = 0; i < DateEx.arguments.length; i++) {
params += "DateEx.arguments[" + i + "],";
}
params = params.substring(0,params.length-1);
var date = eval("new Date(" + params + ")");
this.setTime(date.getTime());
}
// prototype the api calls used by the DateEx class
extern int GetDateFormat(long, unsigned long, void *, char *, char *, int) "kernel32" from "GetDateFormatA";
extern int GetTimeFormat(long, unsigned long, void *, char *, char *, int) "kernel32" from "GetTimeFormatA";
extern int GetLocaleInfo(long, long, char *, int) "kernel32" from "GetLocaleInfoA"
function getSDate() {
// prepare string to receive date from API call
var sdate = new StringEx().replicate(" ",80);
// convert date/time to API SYSTEMTIME structure
var systime = this.getSystemTime();
// API call
var len = GetDateFormat(0,DATE_LONGDATE,systime,0,sdate,sdate.length);
// return without trailing null
return (sdate.substring(0,len-1));
}
function getSDay() {
var localeType = 0;
switch (this.getDay()) {
case 0:
localeType = LOCALE_SDAYNAME7;
break;
case 1:
localeType = LOCALE_SDAYNAME1;
break;
case 2:
localeType = LOCALE_SDAYNAME2;
break;
case 3:
localeType = LOCALE_SDAYNAME3;
break;
case 4:
localeType = LOCALE_SDAYNAME4;
break;
case 5:
localeType = LOCALE_SDAYNAME5;
break;
case 6:
localeType = LOCALE_SDAYNAME6;
}
var sday = new StringEx().replicate(" ",40);
var len = GetLocaleInfo(0,localeType,sday,sday.length);
return (sday.substring(0,len-1));
}
function getSMonth() {
var month = this.getMonth();
var smonth = new StringEx().replicate(" ",40);
var localeType = 0;
switch (month) {
case 0:
localeType = LOCALE_SMONTHNAME1;
break;
case 1:
localeType = LOCALE_SMONTHNAME2;
break;
case 2:
localeType = LOCALE_SMONTHNAME3;
break;
case 3:
localeType = LOCALE_SMONTHNAME4;
break;
case 4:
localeType = LOCALE_SMONTHNAME5;
break;
case 5:
localeType = LOCALE_SMONTHNAME6;
break;
case 6:
localeType = LOCALE_SMONTHNAME7;
break;
case 7:
localeType = LOCALE_SMONTHNAME8;
break;
case 8:
localeType = LOCALE_SMONTHNAME9;
break;
case 9:
localeType = LOCALE_SMONTHNAME10;
break;
case 10:
localeType = LOCALE_SMONTHNAME11;
break;
case 11:
localeType = LOCALE_SMONTHNAME12;
}
var smonth = new StringEx().replicate(" ",40);
var len = GetLocaleInfo(0,localeType,smonth,smonth.length);
return (smonth.substring(0,len-1));
}
function getSTime( seconds, twelve ) {
// prepare string to receive time from API call
var stime = new StringEx().replicate(" ",20);
// set the flags based on the parameters
var flags = (seconds ? 0 : TIME_NOSECONDS) +
(twelve ? 0 : TIME_FORCE24HOURFORMAT + TIME_NOTIMEMARKER);
// convert date/time to API SYSTEMTIME structure
var systime = this.getSystemTime();
// API call
var len = GetTimeFormat(0,flags,systime,0,stime,stime.length);
// return without trailing null
return (stime.substring(0,len-1));
}
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");
}
function getSystemTime() {
//take an IntraBuilder date/time and return a Windows SYSTEMTIME structure:
//typedef struct _SYSTEMTIME { // st
// WORD wYear;
// WORD wMonth;
// WORD wDayOfWeek;
// WORD wDay;
// WORD wHour;
// WORD wMinute;
// WORD wSecond;
// WORD wMilliseconds;
//} SYSTEMTIME;
var year = this.year;
if (year < 100) { // year is in this century
// determine the current century
if (new Date("1/1/1900").getYear() == 0)
year += 1900;
else if (new Date("1/1/2000").getYear() == 0)
year += 2000;
else { // check all the centuries
for (var i = 100; i<=4000; i += 100) {
if (new Date("1/1/" + i).getYear() == 0)
year += i;
}
}
}
var systime = "";
var strEx = new StringEx();
// year
systime += strEx.chr((year) % 256) +
strEx.chr(parseInt((year)/256) % 256);
// month
systime += strEx.chr((this.month+1) % 256) + strEx.chr(0);
// dayOfWeek
systime += strEx.chr((this.day) % 256) + strEx.chr(0);
// day
systime += strEx.chr((this.date) % 256) + strEx.chr(0);
// hour
systime += strEx.chr((this.hour) % 256) + strEx.chr(0);
// minute
systime += strEx.chr((this.minute) % 256) + strEx.chr(0);
// second
systime += strEx.chr((this.second) % 256) + strEx.chr(0);
// millisecond
systime += strEx.chr(0) + strEx.chr(0);
return (systime);
}
}