Does anyone know how to get the actual day (mon, tues, wed, etc) that a file was created? The datetime record doesn't seem to have that info, nor does the searchrec. Is there a way to get this information from a packed date?
TIA...
Jim

Mailing lists / fpc-pascal / 2001-04
16 messages · 9 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Does anyone know how to get the actual day (mon, tues, wed, etc) that a file was created? The datetime record doesn't seem to have that info, nor does the searchrec. Is there a way to get this information from a packed date?
TIA...
Jim
Does anyone know how to get the actual day (mon, tues, wed, etc) that a file was created? The datetime record doesn't seem to have that info, nor does the searchrec. Is there a way to get this information from a packed date?
No, but you can simply calculate it.
FUNCTION LeapYr( Year : LONGINT) : BOOLEAN; ASSEMBLER;asm
push %ebx // ease calls from other procedures push %ecx
push %edx
movl Year,%eax
testl $3,%eax
jne .LLeapEnd
movl $100,%ebx
cltd
idivl %ebx
testb %dl,%dl
jne .LLeapTrue
and $3,%eax
je .LLeapTrue
.LLeapEnd: setb %al
jmp .LLeapExit
.LLeapTrue: movl $1,%ax
.LLeapExit: pop %edx
pop %ecx
pop %ebx
and $1,%al
end ['EAX']; // procedure saves %ebx..%edx, for internal calling.
{ Calculates daynumber, January 1st =1. incl leapyear(LeapYr())
correction }
FUNCTION DayNr( Day, Month, Year: LONGINT) : LONGINT;
ASSEMBLER;
TYPE DyNr=ARRAY[0..11] OF LONGINT;
CONST MonthDays :
DyNr=(0,31,59,90,120,151,181,212,243,273,304,334);ASM
movl Month,%ebx
movl Day,%ecx
cmp $2,%ebx
jbe .LDayNr2
.LDayNr1: push Year
call LeapYr
add %eax,%ecx
.LDayNr2: decl %ebx
movl MonthDays(,%ebx,4),%eax
add %ecx,%eax
END ['EAX','EBX','ECX'];
TYPE Arr12 = ARRAY[0..11] OF BYTE;
TabType=ARRAY[0..3] OF BYTE;CONST TabCent : TabType = (0,6,4,2); { Century correction} TabMonth : Arr12 = (0,3,3,6,1,4,6,2,5,0,3,5); {Month indices}
FUNCTION DOW( Year,Month,Day:LONGINT): LONGINT;
ASSEMBLER;
{ DOW( a Sunday)=0; DOW( a Monday)=1
Ultrafast since it works with tables. }
ASM
xorl %ecx,%ecx
mov Year,%eax
cmp $2000,%eax
jb .LBelow2000
cmp $3,Month
jb .LBelow2000
incl %ecx.LBelow2000: movl $100,%ebx
cltd
idivl %ebx
incl %eax
andl $3,%eax
movzbl TabCent(,%eax),%ebx
// ebx contains century correction
mov Day,%eax
addl %eax,%ebx // Add Day
addl %edx,%ebx // Add Year MOD 100
shrl $2,%edx
addl %edx,%ebx // Add (Year MOD 100) SHR 2
mov Month,%eax // Month
decl %eax
movzbl TabMonth(,%eax),%edx // is index
addl %edx,%ebx // Add TabMonth[Month]
movl $7,%eax
xchgl %eax,%ebx
addl %ecx,%eax
incl %eax
cltdidivl %ebx // Divide total by 7
movl %edx,%eax
END ['EAX','EBX','ECX','EDX'];
begin
end.Marco van de Voort ( or )
No assembler is required; it's easily done in Pascal:
function Weekday(D,M,Y: word): word;
(* Input D=day (1..31), M=month(1..12), Y=year(e.g. 2001) *)
(* Returns 0=Sunday, 1=Monday, ... 6=Saturday *)
const
FD: array[1..12] of byte = (6,2,2,5,0,3,5,1,4,6,2,4);
var
Y1: integer;
begin
if M > 2 then Y1 := Y else Y1 := Y-1;
WeekDay := ((D+(Y1 div 4)-(Y1 div 100)+(Y1 div 400)+Y+FD[M]) mod 7);
end;I hope this helps.
- Rich
Quoting Rich Pasco :
Simpler to understand? (also Delphi based)
function StrWeekday(D,M,Y: word): string;
var
DT: TDate;
begin
Result := FormatDateTime('dddd', EncodeDate(Y, M, D));
end;Who said it had to be optomised ;)
Matt
No assembler is required; it's easily done in Pascal: function Weekday(D,M,Y: word): word;
Rich Pasco wroteNo assembler is required; it's easily done in Pascal:
The following function in the sysutils unit calculates the dayofweek. (sunday is day 1)
function DayOfWeek(DateTime: TDateTime): integer;This _is_ in the documentation.
Michael.
Believe it or not I did search the pdf files, but I looked for weekday instead. I also browsed most of the .pp files in source\rtl for such a function, but didn't see it either. Sorry.
Jim
[snip]
This seems to work very well. Thanks.
One question; does it properly handle leap years? Is that what the "if M > 2 then Y1..." line is for?
Jim
asked, about my function Weekday:
One question; does it properly handle leap years? Is that what the "if M > 2 then Y1..." line is for?
Yes and yes, respectively.
Unlike a call to function DayOfWeek in unit SysUtils, my function Weekday is self-contained; i.e. it encapsulates the entire calendar algorithm in pure Pascal code with no dependence on external libraries. Add a second table giving the number of days in each month and you can draw the calendar of any month you like.
- Rich
[snip] This seems to work very well. Thanks. One question; does it properly handle leap…
At 4/19/01 08:44 AM, you wrote:
Jim,
One question; does it properly handle leap years? Is that what the "if M > 2 then Y1..." line is for?
Both lines contribute to this in their own way. The second line (WeekDay := ...) accounts for the different length of the leap years, the first line makes the algorithm avoid the problems of post-February months (as the extra day is in the middle of the year, calculating pre-Feb 28 days should ignore the current leap year while post-Feb 29 dates should take it into consideration). The algorithm shifts the first two months as if they were the last months of the previous year, thereby shifting the extra day to the end of the year, eliminating the need to handle it individually.
The algorithm is a modification of the ingenious formula invented by a mathematician named Zeller, way before the era of computers (some time in the 19th century, if I remember correctly). He used an even nicer formula, at least nicer for a mathematician, without a table lookup for the various months (with an extra addition and a division), but the actual implementation is certainly faster with a lookup.
Bye,
Gábor
------------------------------------------------------------------- Gabor DEAK JAHN -- Budapest, Hungary.
E-mail: ,
Hi,
I've looked all through the Windows API help system but I've failed to find a method for obtaining the handle of the current console process.
Eg. I start prog.exe. I want prog.exe to find out the handle that points to itself, that Windows has created for it.
Cheers for any help
Andy
Afaik it is GetActiveWindow.
I've looked all through the Windows API help system but I've failed to find a method for…
Subject: [fpc-pascal]Obtaining Windows API handle of a new console.
Hello,
Hi, I've looked all through the Windows API help system but I've failed to
find
a method for obtaining the handle of the current console process. Eg. I start prog.exe. I want prog.exe to find out the handle that points
to
Depends of the type of handle you want to know:
window handle: I think the method proposed by Marco is correct. Although I'm not sure if it doesn't fail under certain circumstances process handle: GetCurrentProcess()
thread handle: GetCurrentThread()
etc. etc.
Regards,
Thomas
Hi again,
I've been experimenting with the ideas you guys gave me:-
Depends of the type of handle you want to know: window handle: I think the method proposed by Marco is correct. Although >
I'm not sure if it doesn't fail under certain circumstances
process handle: GetCurrentProcess() thread handle: GetCurrentThread()
I'm always getting NULL returned when I try to find the console window handle. I assume it's because the console is not actually a window? I've got the thread and process info., but no handle. Even FindWindow returns the same answer.
I think I've been barking up the wrong tree again ;-)
Does this mean I can't send my console app. to the back or bring to the front of the desktop like a can a GUI app.?
Andy
I am using unit oCrt to accept keyboard imput for my application. Now I see that that I…
ncrt & ocrt share the same code base, so the results *should* be exactly the same. "Out of the box" readkey returns the same values as the Borland crt unit, excepting some combinations like Ctrl/Fx and Atl/Fx..
Is your probelm with the standard Linux console, dumb terminal, emulator?
Do I need to modify the "termcap" file in anyway? is this normal or is there a way to correct this?
Normally not required except to trick some pc terminal emulators.
Also make sure you have the latest ncrt from
http://www.cncware.com/fpc.html
Ken
p.s: using SuSE linux 6.4
Interesting bit of history. Thanks for the insight...
Jim
No assembler is required; it's easily done in Pascal: function Weekday(D,M,Y: word): word;
Greetings,
I am using unit oCrt to accept keyboard imput for my application.
Now I see that that I can not "Inkey" the "Pos1" and "End" Keys, they both return #27 just like in ESC
further simple ReadKey's return differant results
if I use crt, ncrt or ocrt!
Do I need to modify the "termcap" file in anyway?
is this normal or is there a way to correct this?
Stefan
p.s: using SuSE linux 6.4
LUFA Speyer (EDV)
email:
tel : +49 (0)6232-629542
fax : +49 (0)6232-629544
http://www.lufa-speyer.de/