Date.Total Seconds Issues in WIndows

Hey all,

I am having a total seconds issue in Windows and I don’t understand this. I have the following date objects defined:

  DIM MyDate As New Date
  
  DIM LaunchDate As New Date(2013,12,3)

Down a little further in the code, I have:

    System.DebugLog("Total Seconds Stuff: "+str(DemoStart.CreationDate.TotalSeconds)+" "+str(LaunchDate.TotalSeconds))
    
    If DemoStart.Exists AND (DemoStart.CreationDate.TotalSeconds < LaunchDate.TotalSeconds) Then
       DemoStart.Delete 
      System.DebugLog("Deleted DemoStart")
    End IF

DemoStart is a folder item. In this case, I am wanting to delete the file if its total seconds is LESS than the total seconds of 12/3/2013. However, that’s not working. In my debug log output I see the following:

[2576] Total Seconds Stuff: 3.464006e+9 3.468874e+9

The first number, 3.464E+9 is DemoStart.CreateData.TotalSeconds.

The second number 3.46887e+9 is LaunchData.TotalSeconds (i.e.: Total seconds for December 12,2013). Well, the total seconds for any file created say like today should be MORE than the total seconds for December 3 of 2013. But it’s not. On some Windows systems, I get the log entry above. On my Windows system, it’s fine. I have no issue.

Why? What am I doing wrong?

Jon

The logic looks correct to me

Are you sure the demo file exists on the machine where the second log entry (“Deleted DemoStart”) is not shown?

If the statememt,

If DemoStart.Exists AND (DemoStart.CreationDate.TotalSeconds < LaunchDate.TotalSeconds) Then

returns FALSE, then it has to be either that the DemoStart file does not exist, OR that the creation date of the file was after the launch date.

Another thing to look for, are you sure the value of the LaunchDate doesn’t perhaps change prior to getting to the IF statement?

LaunchDate can’t change. It’s hard coded.

The computer’s clock is correct.

I am quite sure that DemoStart does exist as the code execution enters the branch of the if statement which it wouldn’t otherwise.

Jon

Try this and see what happens

 System.DebugLog("Total Seconds Stuff: "+format(DemoStart.CreationDate.TotalSeconds,"############")+" "+format(LaunchDate.TotalSeconds,"############"))
    
    If DemoStart.Exists then
  System.DebugLog("File Exists")
   if (DemoStart.CreationDate.TotalSeconds < LaunchDate.TotalSeconds) Then
       DemoStart.Delete 
      System.DebugLog("Deleted DemoStart")
  else
       System.DebugLog("NOT DELETED")
    End IF
end if

and depending on the results… add breakspoints, and watch what happens

OK. Here is some more of my code and the resulting debug logs…I’m still baffled by this…

  DIM LaunchDate As New Date(2013,12,3)
  
  //If not DebugBuild Then
  
  #if TargetMacOS Then
    DemoStart = SOME_FOLDERITEM
  #elseif TargetLinux Then
    DemoStart = SOME_FOLDERITEM
  #Elseif TargetWin32 Then
    DemoStart = SOME_FOLDERITEM
    System.DebugLog("Demo Start ="+DemoStart.ShellPath)   
  #endif
  
  If DemoStart <> Nil Then
    
    System.DebugLog("Total Seconds Stuff:   Start Creation Date is: "+str(DemoStart.CreationDate.TotalSeconds,"0")+" Launch Date is: "+str(LaunchDate.TotalSeconds,"0"))
    
    If DemoStart.Exists AND (DemoStart.CreationDate.TotalSeconds < LaunchDate.TotalSeconds) Then
       DemoStart.Delete

      If DemoStart.LastErrorCode <> FolderItem.NoError Then
        System.DebugLog("There was an error during attempt to delete.  The error code is: "+str(Demostart.LastErrorCode))
      else
        System.DebugLog("Deleted DemoStart")
      End If
      
    End IF
    
    If (DemoStart.Exists = False)  Then //OR (DemoStart.CreationDate < LaunchDate) Then // File does not exist - create it and store the date/time
      
      System.DebugLog("Creating DemoStart")
      
      SaveDate = TextOutputStream.Create(DemoStart)
      
      If DemoStart.LastErrorCode <> 0  or SaveDate.LastErrorCode <> 0 Then
        System.DebugLog("There was an error during attempt to create DemoStart.  The error code is: "+str(DemoStart.LastErrorCode)+"  "+str(SaveDate.LastErrorCode))
      Else
        System.DebugLog("Created DemoStart")
      End If
      
      CurrentSeconds = MyDate.TotalSeconds
      SaveDate.WriteLine(str(CurrentSeconds))
      
      If DemoStart.LastErrorCode <> 0  or SaveDate.LastErrorCode <> 0 Then
        System.DebugLog("There was an error during attempt to save data.  The error code is: "+str(DemoStart.LastErrorCode)+"  "+str(SaveDate.LastErrorCode))
      Else
        System.DebugLog("Saved DemoStart")
      End If
      
      SaveDate.Close
      
      If DemoStart.LastErrorCode <> 0  or SaveDate.LastErrorCode <> 0 Then
        System.DebugLog("There was an error during attempt to close DemoStart.  The error code is: "+str(DemoStart.LastErrorCode)+"  "+str(SaveDate.LastErrorCode))
      Else
        System.DebugLog("Closed DemoStart")
      End If
      
      DemoStart.Visible = False
      
      System.DebugLog("DemoStart CreateDate: "+str(DemoStart.CreationDate.TotalSeconds,"0")+"  Today: "+str(MyDate.TotalSeconds,"0"))
      
      System.DebugLog("Saved DemoStart - Returning")

Now the logs:

00000061 3.23134375 [4624] Demo Start =A_File_Path
00000062 3.23194623 [4624] Total Seconds Stuff: Start Creation Date is: 3398017633 Launch Date is: 3468873600
00000063 3.23273826 [4624] Deleted DemoStart
00000064 3.23294473 [4624] Creating DemoStart
00000065 3.23372364 [4624] Created DemoStart
00000066 3.23389411 [4624] Saved DemoStart
00000067 3.23570371 [4624] Closed DemoStart
00000068 3.23634291 [4624] DemoStart CreateDate: 3398017633 Today: 3475239304
00000069 3.23639917 [4624] Saved DemoStart - Returning

Now, the file was deleted there on line 63 in the log. Now, we recreated it in line 64. Why does the creation date not change? Shouldn’t the creation date of the new file be today? Does Windows cache creation dates based on file names? Because I would think that line 68 would shot that the Total Seconds number should be nearly the same between both values on line 68. That’s what I don’t understand.

Ideas?

Shot it the dark: after you delete the file, get a fresh folderitem for it. If that works, then you’ve found a bug.

It’s just bizarre. Because I can’t make it happen on my machine. But other people see it on theirs.

But I’ll try that.