OSDN Git Service

日付関連の処理のエラー処理追加
authorh677 <h677>
Mon, 8 Mar 2004 13:10:14 +0000 (13:10 +0000)
committerh677 <h677>
Mon, 8 Mar 2004 13:10:14 +0000 (13:10 +0000)
BoardGroup.pas
GikoSystem.pas

index 70d67c8..b951c79 100644 (file)
@@ -360,7 +360,7 @@ type
        function        BBSsFindBoardFromURL( inURL : string ) : TBoard;
        function        BBSsFindBoardFromTitle( inTitle : string ) : TBoard;
        function        BBSsFindThreadFromURL( inURL : string ) : TThreadItem;
-    function   ConvertDateTimeString( inDateTimeString : string) : string;
+    function   ConvertDateTimeString( inDateTimeString : string) : TDateTime;
     
 var
        BBSs            : array of TBBS;
@@ -995,11 +995,11 @@ begin
        try
 //             Round := ini.ReadBool('Status', 'Round', False);
                tmp := ini.ReadString('Status', 'RoundDate', DateTimeToStr(ZERO_DATE));
-        FRoundDate := StrToDateTime(ConvertDateTimeString(tmp));
+        FRoundDate := ConvertDateTimeString(tmp);
         tmp := ini.ReadString('Status', 'LastModified', DateTimeToStr(ZERO_DATE));
-        FLastModified := StrToDateTime(ConvertDateTimeString(tmp));
+        FLastModified := ConvertDateTimeString(tmp);
         tmp := ini.ReadString('Status', 'LastGetTime', DateTimeToStr(ZERO_DATE));
-        FLastGetTime := StrToDateTime(ConvertDateTimeString(tmp));
+        FLastGetTime := ConvertDateTimeString(tmp);
 
         {
                try
@@ -1072,10 +1072,21 @@ begin
 end;
 //\82Æ\82«\82½\82Ü2003 02 08 0:32:13\82±\82ñ\82È\8c`\8e®\82Ì\93ú\95t\82ª\82 \82é\82Ì\82Å\82»\82ê\82ð
 //        2003/02/08 0:32:13\82É\95Ï\8a·\82·\82é
-function       ConvertDateTimeString( inDateTimeString : string) : string;
+function       ConvertDateTimeString( inDateTimeString : string) : TDateTime;
+const
+       ZERO_DATE_STRING : string = '1970/01/01 0:00:00';
 var
        i : Integer;
+    y: Integer;
+    m: Integer;
+    d: Integer;
+    hour: Integer;
+    min: Integer;
+    sec: Integer;
 begin
+    if inDateTimeString = '' then
+       inDateTimeString := ZERO_DATE_STRING;
+
     if ( AnsiPos('/', inDateTimeString ) = 0 ) and
        ( AnsiCompareStr( DateTimeToStr(ZERO_DATE), inDateTimeString) <> 0 ) then begin
                for i := 0 to 1 do begin
@@ -1083,7 +1094,37 @@ begin
                Delete(inDateTimeString, AnsiPos(' ', inDateTimeString), 1);
        end;
     end;
-    Result := inDateTimeString;
+    try
+       Result := StrToDateTime( inDateTimeString );
+    except
+       if( inDateTimeString[5] = '/' ) and ( inDateTimeString[8] = '/' ) then begin
+            y := StrToIntDef( Copy(inDateTimeString, 1, 4), 1970 );
+            m := StrToIntDef( Copy(inDateTimeString, 6, 2), 1 );
+            d := StrToIntDef( Copy(inDateTimeString, 9, 2), 1 );
+            hour := 0; min  := 0; sec  := 0;
+
+               if Length(inDateTimeString) > 11 then begin
+               if( inDateTimeString[13] = ':' ) and ( inDateTimeString[16] = ':' ) then begin
+                       hour := StrToIntDef( Copy(inDateTimeString, 12, 1), 0 );
+                    min  := StrToIntDef( Copy(inDateTimeString, 14, 2), 0 );
+                    sec  := StrToIntDef( Copy(inDateTimeString, 17, 2), 0 );
+                end else if( inDateTimeString[14] = ':' ) and ( inDateTimeString[17] = ':' ) then begin
+                       hour := StrToIntDef( Copy(inDateTimeString, 12, 2), 0 );
+                    min  := StrToIntDef( Copy(inDateTimeString, 15, 2), 0 );
+                    sec  := StrToIntDef( Copy(inDateTimeString, 18, 2), 0 );
+                end;
+            end;
+            try
+               Result := EncodeDateTime(y ,m, d, hour, min, sec, 0);
+            except
+                Result := ZERO_DATE;
+            end;
+        end else
+               Result := ZERO_DATE;
+    end;
+
+
+   // Result := inDateTimeString;
 end;
 // \83T\83u\83W\83F\83N\83gURL\8eæ\93¾
 function TBoard.GetReadCgiURL: string;
@@ -1709,14 +1750,11 @@ begin
        // \83t\83@\83C\83\8b\96¼\82©\82ç\83X\83\8c\8dì\90¬\93ú\8e\9e\82ð\8b\81\82ß\82é
     try
                // \83\8d\83O\83t\83@\83C\83\8b\82Ì\8ag\92£\8eq\82ð\82Í\82¸\82µ\82½\82à\82Ì\82ª\83X\83\8c\8dì\90¬\93ú\8e\9e
-        //if IsLogFile then begin
-            tmp := ChangeFileExt(FFileName, '');
-            if ( Length(tmp) = 9) and ( tmp[1] = '0' ) then
-               Insert('1', tmp, 1);
-            unixtime := StrToInt64(tmp);
-                       Result := UnixToDateTime(unixtime) + OffsetFromUTC;
-        //end else
-        //     Result := ZERO_DATE;
+        tmp := ChangeFileExt(FFileName, '');
+        if ( Length(tmp) = 9) and ( tmp[1] = '0' ) then
+               Insert('1', tmp, 1);
+        unixtime := StrToInt64(tmp);
+        Result := UnixToDateTime(unixtime) + OffsetFromUTC;
        except
                on E: Exception do
                        Result := ZERO_DATE;
index e36c678..7dde639 100644 (file)
@@ -153,7 +153,7 @@ type
                function GetFileLineCount(FileName : string): longint;
                function Get2chDate(aDate: TDateTime): string;
                function IntToDateTime(val: Int64): TDateTime;
-               function DateTimeToInt(ADate: TDateTime): Integer;
+               function DateTimeToInt(ADate: TDateTime): Int64;
 
                function ReadThreadFile(FileName: string; Line: Integer): string;
 
@@ -214,7 +214,7 @@ const
        ZERO_DATE: Integer      = 25569;
        BETA_VERSION_NAME_E = 'beta';
        BETA_VERSION_NAME_J = 'ÊÞÀ';
-       BETA_VERSION                            = 46;
+       BETA_VERSION                            = 47;
        BETA_VERSION_BUILD      = '';                           //debug\94Å\82È\82Ç
        APP_NAME                                                = 'gikoNavi';
 
@@ -464,17 +464,17 @@ var
        d2: tdatetime;
 begin
        d1 := EncodeDate(1970, 1, 1);
-       d2 := (val * 1000) / (24 * 60 * 60 * 1000);
+       d2 := val / 86400.0;//(val * 1000) / (24 * 60 * 60 * 1000);
        Result := d1 + d2;
 end;
 
-function TGikoSys.DateTimeToInt(ADate: TDateTime): Integer;
+function TGikoSys.DateTimeToInt(ADate: TDateTime): Int64;
 var
        d: TDateTime;
        c: Currency;
 begin
        d := EncodeDate(1970, 1, 1);
-       c := (ADate - d) * 24 * 60 * 60;
+       c := (ADate - d) * 86400; //(ADate - d) * 24 * 60 * 60;
        Result := Trunc(c);
 end;
 
@@ -501,6 +501,7 @@ var
        RoundItem: TRoundItem;
        idx: Integer;
        usePlugIn : Boolean;
+    tmpStr: string;
 begin
        Board.Clear;
        UnRead := 0;
@@ -587,8 +588,14 @@ begin
                                if TmpFileList.Find(ChangeFileExt(ThreadItem.FileName, '.tmp'), Index) then begin
                                        ini := TMemIniFile.Create(ChangeFileExt(ThreadItem.GetThreadFileName, '.tmp'));
                                        try
-                                               ThreadItem.RoundDate := ini.ReadDateTime('Setting', 'RoundDate', ZERO_DATE);
-                                               ThreadItem.LastModified := ini.ReadDateTime('Setting', 'LastModified', ZERO_DATE);
+                                               //ThreadItem.RoundDate := ini.ReadDateTime('Setting', 'RoundDate', ZERO_DATE);
+                        tmpStr := ini.ReadString('Setting', 'RoundDate', DateTimeToStr(ZERO_DATE));
+                                       ThreadItem.RoundDate := ConvertDateTimeString(tmpStr);
+
+                                               //ThreadItem.LastModified := ini.ReadDateTime('Setting', 'LastModified', ZERO_DATE);
+                        tmpStr := ini.ReadString('Setting', 'LastModified', DateTimeToStr(ZERO_DATE));
+                                       ThreadItem.LastModified := ConvertDateTimeString(tmpStr);
+
                                                ThreadItem.Size := ini.ReadInteger('Setting', 'Size', 0);
                         if ThreadItem.Size = 0 then begin
                                ThreadItem.Size := FileSizeByName(ThreadItem.FileName) - ThreadItem.Count;