~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to rtl/objpas/sysutils/datih.inc

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2004-08-12 16:29:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040812162937-moo8ulvysp1ln771
Tags: 1.9.4-5
fp-compiler: needs ld, adding dependency on binutils.  (Closes: #265265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
    *********************************************************************
 
3
    $Id: datih.inc,v 1.2 2003/11/26 20:15:46 michael Exp $
 
4
    Copyright (C) 1997, 1998 Gertjan Schouten
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
    *********************************************************************
 
20
 
 
21
    System Utilities For Free Pascal
 
22
}
 
23
 
 
24
 
 
25
type
 
26
  PDayTable = ^TDayTable;
 
27
  TDayTable = array[1..12] of Word;
 
28
 
 
29
const
 
30
   HoursPerDay = 24;
 
31
   MinsPerHour = 60;
 
32
   SecsPerMin  = 60;
 
33
   MSecsPerSec = 1000;
 
34
   MinsPerDay  = HoursPerDay * MinsPerHour;
 
35
   SecsPerDay  = MinsPerDay * SecsPerMin;
 
36
   MSecsPerDay = SecsPerDay * MSecsPerSec;
 
37
 
 
38
   DateDelta = 693594;        // Days between 1/1/0001 and 12/31/1899
 
39
   UnixDateDelta = 25569;
 
40
 
 
41
   { True=Leapyear }
 
42
   MonthDays: array [Boolean] of TDayTable =
 
43
     ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
 
44
      (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
 
45
 
 
46
   TwoDigitYearCenturyWindow : word= 50;
 
47
                             { Threshold to be subtracted from year before
 
48
                               age-detection.}
 
49
 
 
50
   {  date time formatting characters:
 
51
      c      : shortdateformat + ' ' + shorttimeformat
 
52
      d      : day of month
 
53
      dd     : day of month (leading zero)
 
54
      ddd    : day of week (abbreviation)
 
55
      dddd   : day of week (full)
 
56
      ddddd  : shortdateformat
 
57
      dddddd : longdateformat
 
58
      m      : month
 
59
      mm     : month (leading zero)
 
60
      mmm    : month (abbreviation)
 
61
      mmmm   : month (full)
 
62
      y      : year (four digits)
 
63
      yy     : year (two digits)
 
64
      yyyy   : year (with century)
 
65
      h      : hour
 
66
      hh     : hour (leading zero)
 
67
      n      : minute
 
68
      nn     : minute (leading zero)
 
69
      s      : second
 
70
      ss     : second (leading zero)
 
71
      t      : shorttimeformat
 
72
      tt     : longtimeformat
 
73
      am/pm  : use 12 hour clock and display am and pm accordingly
 
74
                a/p    : use 12 hour clock and display a and p accordingly
 
75
      /      : insert date seperator
 
76
      :      : insert time seperator
 
77
      "xx"   : literal text
 
78
      'xx'   : literal text
 
79
   }
 
80
 
 
81
type
 
82
{$ifndef win32}
 
83
   { Win32 reuses the struct from the Windows unit }
 
84
   TSystemTime = record
 
85
      Year, Month, Day: word;
 
86
      Hour, Minute, Second, MilliSecond: word;
 
87
   end ;
 
88
{$endif win32}
 
89
 
 
90
   TTimeStamp = record
 
91
      Time: integer;   { Number of milliseconds since midnight }
 
92
      Date: integer;   { One plus number of days since 1/1/0001 }
 
93
   end ;
 
94
 
 
95
 
 
96
function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
 
97
function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
 
98
function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
 
99
function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
 
100
function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean;
 
101
function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean;
 
102
function EncodeDate(Year, Month, Day :word): TDateTime;
 
103
function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
 
104
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
 
105
function DecodeDateFully(const DateTime: TDateTime; var Year, Month, Day, DOW: Word): Boolean;
 
106
procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
 
107
procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
 
108
function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
 
109
function DayOfWeek(DateTime: TDateTime): integer;
 
110
function Date: TDateTime;
 
111
function Time: TDateTime;
 
112
function Now: TDateTime;
 
113
function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
 
114
function IsLeapYear(Year: Word): boolean;
 
115
function DateToStr(Date: TDateTime): string;
 
116
function TimeToStr(Time: TDateTime): string;
 
117
function DateTimeToStr(DateTime: TDateTime): string;
 
118
function StrToDate(const S: string): TDateTime;
 
119
function StrToTime(const S: string): TDateTime;
 
120
function StrToDateTime(const S: string): TDateTime;
 
121
function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
 
122
procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
 
123
Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
 
124
Function FileDateToDateTime (Filedate : Longint) :TDateTime;
 
125
 
 
126
{ FPC Extra }
 
127
Procedure GetLocalTime(var SystemTime: TSystemTime);
 
128
 
 
129
{
 
130
  $Log: datih.inc,v $
 
131
  Revision 1.2  2003/11/26 20:15:46  michael
 
132
  TwoDigitYearCenturyWindow is 50
 
133
 
 
134
  Revision 1.1  2003/10/06 21:01:06  peter
 
135
    * moved classes unit to rtl
 
136
 
 
137
  Revision 1.8  2003/01/18 23:45:37  michael
 
138
  + Fixed EncodeDate/Time so they use TryEncodeDate/Time
 
139
 
 
140
  Revision 1.7  2002/12/25 01:03:48  peter
 
141
    * some date constants added
 
142
 
 
143
  Revision 1.6  2002/10/02 21:04:06  peter
 
144
    * For win32 use the tsystemtime from the windows unit, that is changed
 
145
      to a variant record with compatibile field names
 
146
 
 
147
  Revision 1.5  2002/09/07 16:01:22  peter
 
148
    * old logs removed and tabs fixed
 
149
 
 
150
}