Purebasic 6.x file creation date

Just starting out? Need help? Post your questions and find answers here.
Rjevsky
User
User
Posts: 27
Joined: Tue Jul 18, 2017 3:41 pm

Purebasic 6.x file creation date

Post by Rjevsky »

Strange behavior when working with file creation dates. The issue is observed in the 6.x series.

Code: Select all

FullPath.s=GetCurrentDirectory()+"Text.txt"
  If CreateFile(0, FullPath)        
    For a=1 To 10
      WriteStringN(0, "Line "+Str(a)) 
    Next
    For a=1 To 10
      WriteString(0, "String"+Str(a))  
    Next
    CloseFile(0)                       
  Else
    MessageRequester("Information","may not create the file!")
  EndIf




Debug SetFileDate(FullPath,#PB_Date_Modified,ParseDate("%yyyy%mm%dd%hh%ii", "201408251415"))
DateCr = GetFileDate(FullPath, #PB_Date_Modified)
Debug Str(DateCr)
Debug FormatDate("%yyyy%mm%dd%hh%ii", DateCr)
output:
1
1408979700
201408251515
Little John
Addict
Addict
Posts: 4869
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Purebasic 6.x file creation date

Post by Little John »

This issue happens also with other years, but apperently only with months when daylight saving time is in effect – at least here on Windows 11 with a NTFS filesystem.

Code: Select all

; PB 6.30

EnableExplicit

#DateMask$ = "%yyyy-%mm-%dd %hh:%ii:%ss"

Define file$, year.i, month.i, DateSet.q, DateGet.q

file$ = GetUserDirectory(#PB_Directory_Desktop) + "text.txt"

If CreateFile(0, file$) = 0
   MessageRequester("Error", "Can't create file" + #LF$ +
                             file$)
   End
EndIf

WriteString(0, "x")  
CloseFile(0)

year = 2025

Debug "Year: " + year
Debug ""

For month = 1 To 12
   DateSet = Date(year, month, 25, 14, 15, 0)
   
   If SetFileDate(file$, #PB_Date_Modified, DateSet) = 0
      MessageRequester("Error", "Can't set the date of file" + #LF$ +
                                file$)
      End
   EndIf
   DateGet = GetFileDate(file$, #PB_Date_Modified)
   
   If DateSet <> DateGet
      Debug "Month: " + month
      Debug "Set: " + FormatDate(#DateMask$, DateSet)
      Debug "Get: " + FormatDate(#DateMask$, DateGet)   ; 1 hour later from months 4 to 10
      Debug ""
   EndIf
Next
Rjevsky
User
User
Posts: 27
Joined: Tue Jul 18, 2017 3:41 pm

Re: Purebasic 6.x file creation date

Post by Rjevsky »

I have this problem on Windows 10, using NTFS. However, my time zone doesn't observe daylight saving time. PureBasic 5.72 doesn't have this problem.
Post Reply