home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
msysjour
/
vol04
/
02b
/
project
/
act
/
date.act
next >
Wrap
Text File
|
1988-11-30
|
4KB
|
168 lines
/*
Miscellaneous methods to load along with DATE.CLS.
Adam Rauch
8/26/88
11/30/88 mzu -added test in String:asDate to use international
date format (e.g. MMDDYY or DDMMYY etc).
*/
now(Stream)!!
/* Parse an integer from a Stream. If not found,
return the default value. */
Def parseInt(self, delimiter, def | word result)
{ if (word := word(self:Stream, delimiter))
cand (result := asInt("0" + word, 10))
^result
else
^def
endif
}!!
now(Long)!!
/* Return date -- self is number of days since 1/1/1901. */
Def asDate(self | aDate daysIntoYear remain withinLeap afterLeap)
{ aDate := new(Date);
remain := asInt((self + 366L) mod 1461L);
withinLeap := afterLeap := 0;
if remain > 58
afterLeap := 1;
if remain < 366
withinLeap := 1
endif;
endif;
if remain < 366
daysIntoYear := remain
else
daysIntoYear := (remain - 1) mod 365
endif;
aDate.month := daysIntoYear / 31 + 2;
if daysBeforeMonth(aDate:Date) > (daysIntoYear - withinLeap:Int):Int
aDate.month := aDate.month - 1
endif;
if remain == 59
withinLeap := 0
endif;
aDate.year := asInt(((self + 366L)/1461L):Long)*4 + ((remain - afterLeap:Int)/365):Int + 1900;
aDate.day := daysIntoYear - withinLeap:Int - daysBeforeMonth(aDate:Date):Int + 1;
^aDate
}!!
now(Int)!!
/* Return a Date given month, day, and year. Assume
twentieth century if a two-digit year is given. */
Def date(self, day, year | aDate)
{ aDate := new(Date);
aDate.month := self;
aDate.day := day;
if year < 100
aDate.year := year + 1900
else
aDate.year := year
endif;
^isValid(aDate:Date)
}!!
now(String)!!
/* Return a Date object parsed according to international date format */
Def asDate(self | iDate)
{
iDate := getProfileString("intl", "iDate");
select
case iDate = "2"
^asYYMMDDDate(self);
endCase
case iDate = "1"
^asDDMMYYDate(self);
endCase
default /* "0" or not found */
^asMMDDYYDate(self);
endSelect;
}!!
/* Return a Date object parsed from a short form MM/DD/YY string like
"12/31/87" or "12/31/1987". Assume twentieth century if a two-digit
year is given. */
Def asMMDDYYDate(self | aDate aStream)
{ aDate := new(Date);
aStream := streamOver(self:String);
aDate.month := parseInt(aStream:Stream, '/', 0);
aDate.day := parseInt(aStream:Stream, '/', 0);
aDate.year := parseInt(aStream:Stream, '/', 0);
if aDate.year < 100
aDate.year := aDate.year + 1900
endif;
^isValid(aDate:Date)
}!!
/* Return a Date object parsed from a short form DD/MM/YY string like
"31/12/87" or "31/12/1987". Assume twentieth century if a two-digit
year is given. */
Def asDDMMYYDate(self | aDate aStream)
{ aDate := new(Date);
aStream := streamOver(self:String);
aDate.day := parseInt(aStream:Stream, '/', 0);
aDate.month := parseInt(aStream:Stream, '/', 0);
aDate.year := parseInt(aStream:Stream, '/', 0);
if aDate.year < 100
aDate.year := aDate.year + 1900
endif;
^isValid(aDate:Date)
}!!
/* Return a Date object parsed from a short form YY/MM/DD string like
"87/12/31" or "1987/12/31". Assume twentieth century if a two-digit
year is given. */
Def asYYMMDDDate(self | aDate aStream)
{ aDate := new(Date);
aStream := streamOver(self:String);
aDate.year := parseInt(aStream:Stream, '/', 0);
aDate.month := parseInt(aStream:Stream, '/', 0);
aDate.day := parseInt(aStream:Stream, '/', 0);
if aDate.year < 100
aDate.year := aDate.year + 1900
endif;
^isValid(aDate:Date)
}!!
/* Return the string from win.ini for this app(self)/key.
If not found, return zero-length string.
This method is in Actor 1.2A and later. */
Def getProfileString(self, key | str len dStr ans)
{ str := new(String, 80);
dStr := "";
len := Call GetProfileString(lP(self), lP(key),
lP(dStr), lP(str), 80
);
ans := subString(getText(str), 0, len);
freeHandle(self);
freeHandle(key);
freeHandle(dStr);
freeHandle(str);
^ans;
}!!