Another tick question

Started by stanl, October 22, 2021, 12:56:27 PM

Previous topic - Next topic

stanl

As the last thread about ticks may move off base, I do have another interesting value to investigate: Below is the script you sent with a modified tick number to move past midnight, modified the return values for both UTC and Local Time. Then queried the day of the week which = 3 [Wednesday] and would be correct for the UTC value. I observed a TryKind() method and a Kind property but couldn't incorporate into script snippet so that the DayOfWeek would return 2 if I wanted to know local time. This might seem a trivial point.
Code (WINBATCH) Select


tick =  '635241315000000000'
Ticks =  ObjectType('i8',tick)
Date1 = ObjectClrNew("System.DateTime",Ticks)
strDate = Date1.ToUniversalTime()  ;ToString()
strDate1 = Date1.ToLocalTime()
dow = Date1.DayOfWeek
Message("Day of Week ":dow,strDate:@LF:strDate1)
exit

td

DateTime class constructors have multiple overloads.  I tried the constructor with the DateTimeKind parameter but that seems to be ignored by the class. Don't know why.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

The kludge below serves my purpose. Just had to remember how to address the start day of week. [and I know the vbscript function could be replaced with pure WB]
Code (WINBATCH) Select


days = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
netdays = "Monday Tuesday Wednesday Thursday Friday Saturday Sunday"
tick =  '635241315000000000'
Ticks =  ObjectType('i8',tick)
Date1 = ObjectClrNew("System.DateTime",Ticks)
strDate = Date1.ToUniversalTime()
strDate1 = Date1.ToString()
strDate2 = TimeFormat(Date1.ToLocalTime(),"MM/dd/yyyy hh:mm:ss t")
dow = Date1.DayOfWeek
;Message("Day of Week ":dow,strDate:@LF:strDate1:@LF:strDate2)
day=ItemExtract(dow,netdays," ")
Message(".Net Day of Week UniversalTime ":strDate1,"Tick:":tick:@LF:dow:@LF:day)
oS = CreateObject("MSScriptControl.ScriptControl")
oS.Language = "VBScript"
oS.AllowUI = @FALSE
u=oS.Eval(: 'WeekDay("%strDate2%")')
oS = 0
day=ItemExtract(u,days," ")
Message("VBScript Day of Week LocalTime ":strDate2,"Tick:":tick:@LF:u:@LF:day)
exit