FileSetTime: Sommer-/Winterzeit? Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
LuckyJoe
Posts: 335
Joined: 02 Oct 2013, 09:52

FileSetTime: Sommer-/Winterzeit?

04 Dec 2018, 04:12

Hallo zusammen,

mir ist im Zusammenhang mit FileSetTime aufgefallen, dass die Funktion offensichtlich Sommer- bzw. Winterzeit berücksichtigt!?!
So stellt folgender Aufruf (heute, in der Winterzeit):

Code: Select all

FileSetTime, 20181106160800, d:\xxx\Test.csv
den Zeitpunkt der letzten Änderung der angegebenen Datei auf 06.11.2018, 16:08:00 (Datum in der Winterzeit) - so weit so gut...
Mit folgendem Aufruf:

Code: Select all

FileSetTime, 20180906160800, d:\xxx\Test.csv
wird der Zeitpunkt der letzten Änderung aber auf 06.09.2018, 17:08:00 gesetzt (Datum in der Sommerzeit) - das möchte ich aber nicht.
Muss ich jetzt immer im Script berücksichtigen, ob wir Sommer- oder Winterzeit haben und dementsprechend ggf. eine Stunde weniger rechnen? Oder gibt es eine elegantere Möglichkeit?

Danke im Voraus!
HG - Lucky Joe
Herzliche Grüße aus dem Rheinland
Lucky Joe
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: FileSetTime: Sommer-/Winterzeit?

04 Dec 2018, 08:56

z.B. wenn du dir ausrechnest, ob Sommer- oder Winterzeit ist

Code: Select all

MsgBox % IsSummerTime("20180228")			; Winter
MsgBox % IsSummerTime("20180401")			; Sommer
MsgBox % IsSummerTime(A_YYYY A_MM A_DD)		; Heute (20181204) Winter
MsgBox % IsSummerTime("20180931")			; Sommer
MsgBox % IsSummerTime("20181101")			; Winter

IsSummerTime(Date)
{
	if (Date >= LastSunday(A_YYYY "03")) && (Date < LastSunday(A_YYYY "10"))
		return true
	return false
}

LastSunday(Date)
{
	Date += 31, D
	Date := SubStr(Date, 1, 6)
	Date += -1, Day
	FormatTime, WD, %Date%, WDay
	Date += -(WD - 1), D
	return SubStr(Date, 1, 8)
}
geht bestimmt auch schöner bzw elegantere Möglichkeiten

Sollten wir dann auch hier im Tut von 'just me' mit aufnehmen (https://autohotkey.com/boards/viewtopic ... 11&t=10600)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
LuckyJoe
Posts: 335
Joined: 02 Oct 2013, 09:52

Re: FileSetTime: Sommer-/Winterzeit?

04 Dec 2018, 11:14

Danke für die Funktionen, jNizM, funktionieren tadellos.
Ich hatte bei meiner Recherche u.a. einen Threat von dir hier gefunden: https://autohotkey.com/boards/viewtopic.php?f=7&t=406 .
Gibt es nicht auch eine Möglichkeit, per DllCall festzustellen, ob die System-/Local-Time Sommer-/Winterzeit auswirft?
Irgendwo hatte ich auch von MS die Funktion "TimeZoneInfo.IsDaylightSavingTime" gefunden (kernel32.dll?), aber meine Programmierkenntnisse reichen leider nicht aus, um das mit AHK abzugreifen.

Danke nochmals!
HG - Lucky Joe
Herzliche Grüße aus dem Rheinland
Lucky Joe
garry
Posts: 3720
Joined: 22 Dec 2013, 12:50

Re: FileSetTime: Sommer-/Winterzeit?

04 Dec 2018, 14:15

script vom user 'tmplinshi'
https://autohotkey.com/boards/viewtopic ... 28&t=46997
synchronize time

Code: Select all

;- this script user 'tmplinshi' :
;- https://autohotkey.com/boards/viewtopic.php?f=28&t=46997 ---

;- https://www.timeanddate.com/time/dst/
;- https://www.timeanddate.com/worldclock/
;- https://www.science.co.il/language/Locale-codes.php
;- 歐洲 CET / CEST Central European Summer-Time
;-----------------------------------------------------

#warn
setworkingdir,%a_scriptdir%

; 以管理员身份运行
if !A_IsAdmin {
    try
	Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
	ExitApp
}

global dst

if SynTime.DoIt()
    msgbox, 262208,SUCCESS ,Succes synchronized %dst%
else
    msgbox, 262208,NO SUCCESS ,	NO Succes synchronized CET
return

/*
if SynTime.DoIt()
	MsgBox, 64, 成功 , 同步北京时间成功!
else
	MsgBox, 48, 失败 , 同步失败!
; 同步北京时间。用法: SynTime.DoIt()
*/


Class SynTime
{
	DoIt() { ; 成功返回 1
		return this.SetLocalTime( this.BeijingTime() )
	}
	SetLocalTime(YYYYMMDDHHMISS) {
		FormatTime, t, %YYYYMMDDHHMISS%, yyyy/M/1/d/H/m/s/0
		VarSetCapacity(SystemTime, 16, 0)
		Loop, Parse, t, /
			NumPut(A_LoopField, SystemTime, (A_Index-1)*2, "UShort")
		return DllCall("SetLocalTime", "Ptr", &SystemTime)
	}
	BeijingTime() { ; 返回 YYYYMMDDHHMISS
		whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
		whr.Open("HEAD", "http://baidu.com", true)
		whr.Send()
		whr.WaitForResponse()
		_date := whr.GetResponseHeader("Date") ; 示例数据: Mon, 21 Apr 2014 14:58:23 GMT
		arr := StrSplit( _date, [A_Space, ":"] )
		oMonth := {Jan:"01",Feb:"02",Mar:"03",Apr:"04",May:"05",Jun:"06",Jul:"07",Aug:"08",Sep:"09",Oct:"10",Nov:"11",Dec:"12"}
		Mon    := oMonth[ arr.3 ] ; 月份英文缩写转换成数字
		timestamp := arr.4 Mon arr.2 arr.5 arr.6 arr.7 ; YYYYMMDDHHMISS 格式的日期
		CET:=1                             ;- ( UTC + 1 / CET - Central European Time - begin last sunday in octobre / e.g  sun 2018-10-28 03:00>02:00 )
        stringmid,q,timestamp,1,8
        stringmid,Y,timestamp,1,4
        q:=(q)
        lsm := LastSunday(Y . "03")
        lso := LastSunday(Y . "10")
        if (q >= lsm) and (q < lso)
           {
		   DST:="CEST summertime UTC+2"
           CET:=(CET+1)                     ;- ( UTC + 2 / CEST - Central European SUMMER Time - DST begin last sunday in mars / e.g. sun 2018-03-25 02:00>03:00 )
           timestamp += +CET,hours
           }
        else
		   {
		   DST:="CET normaltime UTC+1"
           timestamp += +CET,hours
		   }
		;timestamp += 8, Hours ; 加 8 小时就是北京时间
		return timestamp
	}
}

;-----------------------------------------------------------------------
;- Function last sunday in mars and october for DST daylight saving time
;- https://autohotkey.com/board/topic/97664-find-specific-wday/ ---
LastSunday(Date)
    {
    Date += 31, D
    Date := SubStr(Date, 1, 6)
    Date += -1, Day
    FormatTime, WD , %Date%, WDay
    Date += -(WD - 1), D
    return, SubStr(Date, 1, 8)
   }
;============================================================================
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 03:14

Moin,

wenn man nur wissen will, ob jetzt hier und heute in der für den Rechner gewählten Zeitzone Sommer- oder Winterzeit ist, sollte das auch tun:

Code: Select all

#NoEnv
MsgBox, 0, Wir haben ..., % (IsDST() ? "... Sommerzeit" : "... Winterzeit")
ExitApp
; --------------------------------------------------------------------------------------------------------------------------------
; Returns True if the system is operating in the range of daylight saving settings, otherwise False.
; GetTimeZoneInformation   -> docs.microsoft.com/en-us/windows/desktop/api/timezoneapi/nf-timezoneapi-gettimezoneinformation
; TIME_ZONE_INFORMATION    -> docs.microsoft.com/de-de/windows/desktop/api/timezoneapi/ns-timezoneapi-_time_zone_information
; --------------------------------------------------------------------------------------------------------------------------------
IsDST() {
   VarSetCapacity(TZI, 44 + (64 << !!A_IsUnicode), 0)
   Return !!(DllCall("GetTimeZoneInformation", "Ptr", &TZI, "UInt") = 2) ; 2 = TIME_ZONE_ID_DAYLIGHT
}
Das Phänomen mit der Zeitabweichung, wenn man sie aus einer anderen Zeitzone heraus setzt, irritiert mich aber gewaltig.
Last edited by just me on 05 Dec 2018, 03:52, edited 1 time in total.
User avatar
LuckyJoe
Posts: 335
Joined: 02 Oct 2013, 09:52

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 03:36

@garry: Danke für das Script, aber das synchronisiert offensichtlich nur die Systemzeit. Ich blicke durch die Klasse nicht so ganz durch, wobei ich die chinesischen Kommentare recht nett finde ;-)
Die "LastSunday(Date)"-Funktion ist aber identisch mit der von jNizM.

@justme: Danke - das ist genau die Funktion, die ich gesucht habe, kurz und knackig (auch wenn ich DLLCalls noch nicht wirklich durchblicke) :bravo:
... dann wäre das doch was für die Sammlung, die schon jNizM angesprochen hatte: https://autohotkey.com/boards/viewtopic ... 11&t=10600.
Herzliche Grüße aus dem Rheinland
Lucky Joe
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 04:15

Also Zeitzonen an sich sind ne Sache die sollte man mal anders lösen.
Über Sommer und Winterzeit will ich gar nicht erst anfangen.
Recommends AHK Studio
garry
Posts: 3720
Joined: 22 Dec 2013, 12:50

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 05:06

script von tmplinshi liest von http://www.baidu.com/ UTC aus ( China hat +8h ohne DST )
habe script gebraucht für den alten Computer dessen Lithium Batterie defekt war um die Zeit zu setzen
kann ich den einfachen script von 'just me' verwenden um die Computer-Zeit zu setzen ? ( DllCall("SetLocalTime", "Ptr", &SystemTime) )
Sommerzeit sollte in Europa abgeschafft werden ... (?)
https://www.timesofmalta.com/articles/v ... ock.691589

Image
hier wieder mal kompliziert ...

Code: Select all

;-------- saved at Dienstag, 4. Dezember 2018 18:19:31 --------------
;;-------- https://autohotkey.com/boards/viewtopic.php?f=28&t=46997 ---
;- modified= 20180910
;- created = 20180910
;- descript= show time e.g. 7-Countries / synchronize time / change time ( for test or if needed ( or if no internet-connection) )
;- DST     = only calculate  CET Central-European-Time
;- https://www.timeanddate.com/time/dst/
;- https://www.timeanddate.com/worldclock/
;- https://www.science.co.il/language/Locale-codes.php
;- https://autohotkey.com/boards/viewtopic.php?f=28&t=46997  
;             ( UTC + 1 / CET  - Central European        Time - begin last sunday in octobre / e.g  sun 2018-10-28 03:00>02:00 UTC 01:00)
;             ( UTC + 2 / CEST - Central European SUMMER Time - begin last sunday in mars    / e.g. sun 2018-03-25 02:00>03:00 UTC 01:00)  
;- https://en.wikipedia.org/wiki/Summer_Time_in_Europe
;- On 8  February 2018, the European Parliament voted to ask the European Commission to re-evaluate DST in Europe.
;- On 31 August   2018, the European Commission announced that they, after a web query giving high support of not switching clock twice annually, intend to go ahead with a new directive.  
/*
A formula which cn be used to calculate the beginning of European Summer Time is:
Sunday (31 − ((((5 × y) ÷ 4) + 4) mod 7)) March at 01:00 UTC
The corresponding formula for the end of European Summer Time is:
Sunday (31 − ((((5 × y) ÷ 4) + 1) mod 7)) October at 01:00 UTC
where y is the year, and a mod b is b times the fractional part of a/b. These formulae are valid until 2099
*/
  
       
#warn
#NoEnv
#singleinstance,force
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
Fileencoding,UTF-8
Autotrim,off
SplitPath,a_scriptfullpath, name, dir, ext, name_no_ext, drive
name1=%name_no_ext%
gosub,createsecondscript
gosub,3rdscript
;- country , +/-hours , DST , Language
e4x=
(Ltrim Join`r`n
UTC_GMT    ,0,N,L2057
Portugal   ,0,Y,L2070
Switzerland,1,Y,L2055
Finland    ,2,Y,L1035
China      ,8,N,L2052
Vietnam    ,7,N,L1066
Montevideo ,-3,N,L11274
)
wa:=A_screenwidth
ha:=A_screenHeight
xx:=105
GW  :=(wa*50) /xx   
GH  :=(ha*33) /xx      
Info=%a_osversion% | %a_ostype% | 64bit=%a_is64bitos% | %wa%*%ha% | %a_username%=%a_isadmin% | %a_computername% | AHK=%a_ahkversion%
Gui,2:default
Gui,2: -DPIScale
SS_REALSIZECONTROL := 0x40
Gui,2:Color,Black
Gui,2:Color,ControlColor, Black
Gui,2:Font,s12 cYellow,Lucida Console
;A_GuiFont     := GuiDefaultFont()
;A_GuiFontSize := A_LastError
;aac:= a_screendpi   ;- 168 at 4k
;=================================================
sectA=Country,DATE       TIME,DaylightSavingTime DST,Language
stringsplit,k,sectA,`,
           columns:=k0   ;- 4
SectB=SYNC-TIME,ChangeTime,Worldclock,LanguageCode
stringsplit,b,sectB,`,
;------------------------------		   
rows:=9
all :=(rows*columns)     ;- 36
;------------------------------		   
d :=(wa*.3)/xx     ;-  difference horizontal
h :=(ha* 2)/xx     ;-  ROW-height
w :=(wa*11)/xx     ;- xROW-width
i:=0
r:=0
e:=0
q:=0
s:=3
col:=""
Loop,%all%
  {
  ;-----------------
  M:=mod(i,columns)
  if m=0             ;- skip to next line
     R++
  ;-----------------	 
  ;--- (Line-1) first line text 	 
  if (m=0 and R=1)
    {
	x :=(wa*.5)/xx
    y :=(ha* 1)/xx
    Gui,2:add,text,section x%x% y%y% w0 h0,
	}
  if (R=1)	
    Gui,2:Add,text,ys x+%d% h%h% w%w% ,% k%a_index%
	
  ;--- ( Line 2-8 )second line begin with EDIT ED1... ED28	
  if (m=0 and R>1 and R<9)
    {
	x :=(wa*.5)/xx
    y :=(ha* s)/xx
	s :=(s+3)      ;- add difference vertikal 
    Gui,2:add,text,section x%x% y%y% w0 h0,
	}
  if (R>1 and R<9)
    {
    e++	
	if (e=2 or e=6 or e=10 or e= 14 or e=18 or e=22 or e=26)
      col=Gray
	else
      col=D5E66D  ;-yellow	
	Gui,2:Add,Edit , ys  x+%d%  w%w% h%h% vED%e% c%col% readonly left,
	}
  
  ;------------ Line 9  ------------	 
  if (m=0 and R>8 and R<10)
    {
	x :=(wa*.5)/xx
    y :=(ha* s)/xx
	s :=(s+3) 
    Gui,2:add,text,section x%x% y%y% w0 h0,
	}
  if (R>8 and R<10)
    {
	q++
	;Gui,2:add,button, ys x+%d% w%w% h%h% gStart2,% b%q%
    Gui,2:Add,Progress,ys x+%d% w%w% h%h%  Disabled BackgroundGray
    if (q<2)
      Gui,2:Add,Text,     xp   yp  wp  hp   cYellow    BackgroundTrans Center 0x200 gStart2 ,% b%q%
    else
      Gui,2:Add,Text,     xp   yp  wp  hp   cBlack     BackgroundTrans Center 0x200 gStart2 ,% b%q%
	}
  i++
  }
;----------------  
y :=(ha*27   )/xx
x :=(wa*11.92)/xx   
Gui,2:Add,Edit ,x%x% y%y%  w%w% h%h% vTimex readonly left,
y :=(ha*30)/xx
x :=(wa* 1)/xx   
Gui,2:Add,text ,x%x% y%y%  cGray center,%info% 
  
Gui,2:show, x100 y5 w%gw% h%gh% ,%name1%
settimer,clock,1000
settimer,a0,1000
return
;--------------
2Guiclose:
exitapp
;--------------
Start2:
gui,2:submit,nohide
r:= a_guicontrol
goto,%r%
return
;--------------
changetime:
try
run,%f1%
return
sync-time:
try
run,%f31%
return
;--------------
dst:
run,https://www.timeanddate.com/time/dst/
return
;--------------
worldclock:
run,https://www.timeanddate.com/worldclock/
return
;--------------
languagecode:
run,https://www.science.co.il/language/Locale-codes.php
return
;--------------
clock:
GuiControl,2: ,timex, %A_YYYY%-%A_MM%-%A_DD% %a_hour%:%a_min%:%a_sec%
return
;--------------
a0:
;UTC       := GetTimestampUTC()
UTC:=a_nowutc
e=
Loop,parse,e4x,`n,`r
  {
  x:=a_loopfield
  if x=
     continue
  stringsplit,p,x,`,
  country:=p1
  p1:=utc
  if (p3="Y")
     {
     gosub,cc
     continue
     }
  else
     {
     p1 += +P2,hours
     FormatTime,px, %p1% %p4%,MMMM dddd
     FormatTime,p1, %p1% %p4%,yyyy-MM-dd HH:mm:ss
     e .= country . "," . p1 . ",NO DST," . px . "`r`n"
     continue
     }
  }
;msgbox,%e%
i=0
Loop,parse,e,`n,`r
   {
   stringsplit,d,a_loopfield,`,
   loop,4
      {
	  i++
      GuiControl,2:,ed%i%,% d%a_index%
	  }
   }
e=
return
;---------------------------
cc:
stringmid,q,p1,1,8
stringmid,Y,p1,1,4
q:=(q)
lsm := LastSunday(Y . "03")
lso := LastSunday(Y . "10")
if (q >= lsm) and (q < lso)
   {
   p2:=(P2+1)
   p1 += +P2,hours
   FormatTime,px, %p1% %p4%,MMMM dddd
   FormatTime,p1, %p1% %p4%,yyyy-MM-dd HH:mm:ss
   e .= country "," p1 ",-Summer-Time," px "`r`n"
   }
else
   {
   p1 += +P2,hours
   FormatTime,px, %p1% %p4%,MMMM dddd
   FormatTime,p1, %p1% %p4%,yyyy-MM-dd HH:mm:ss
   e .= country "," p1 ",-NORMAL-TIME," px "`r`n"
   }
return
;--------------------------
;-----------------------------------------------------------------------
;- Function last sunday in mars and october for DST daylight saving time
;- https://autohotkey.com/board/topic/97664-find-specific-wday/ ---
LastSunday(Date)
    {
    Date += 31, D
    Date := SubStr(Date, 1, 6)
    Date += -1, Day
    FormatTime, WD , %Date%, WDay
    Date += -(WD - 1), D
    return, SubStr(Date, 1, 8)
   }
return
;============================================================================
createsecondscript:
f1=%a_scriptdir%\%name1%-change-time.ahk
IfNotExist,%f1%
{
e4x=
(LTrim Join`r`n % `
adm:=a_isadmin
if (adm=0)
Gosub, RunAsAdmin1
;-----------
stringmid,h,a_now,9,2
stringmid,m,a_now,11,2
stringmid,s,a_now,13,2
now:=h . "." . m . "." . s
;- Set time
runwait,%comspec% /k date /T&time /T&time
return
;--------------------------------------------------------------------
RunAsAdmin1:
  Try
  Run, *RunAs "%A_ScriptFullPath%"
Exitapp		
Return
;--------------------------------------------------------------------
RunAsAdmin2:
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
  try
  {
  if A_IsCompiled
    Run *RunAs "%A_ScriptFullPath%" /restart
      else
    Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
  }
ExitApp
}
return
)
fileappend,%e4x%,%f1%
}
return
;=================== end script DateandTime.com ===========================
;- function SYNCHRONIZE user tmplinshi
;- https://autohotkey.com/boards/viewtopic.php?f=28&t=46997
3rdscript:
f31=%a_scriptdir%\%name1%-SYNC-time.ahk
IfNotExist,%f31%
{
e5x=
(LTrim Join`r`n %
;-------- saved at Montag, 10. September 2018 22:24:45 --------------
;;-------- https://autohotkey.com/boards/viewtopic.php?f=28&t=46997 ---
;- this script :
;- https://autohotkey.com/boards/viewtopic.php?f=28&t=46997 ---
;- https://www.timeanddate.com/time/dst/
;- https://www.timeanddate.com/worldclock/
;- https://www.science.co.il/language/Locale-codes.php
;- 歐洲 CET / CEST Central European Summer-Time
;-----------------------------------------------------
#warn
setworkingdir,%a_scriptdir%
; 以管理员身份运行
if !A_IsAdmin {
    Try
	Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
	ExitApp
}
global dst
if SynTime.DoIt()
    msgbox, 262208,SUCCESS ,Succes synchronized %dst%,1
else
    msgbox, 262208,NO SUCCESS ,	NO Succes synchronized CET,1
return
/*
if SynTime.DoIt()
	MsgBox, 64, 成功 , 同步北京时间成功!
else
	MsgBox, 48, 失败 , 同步失败!
; 同步北京时间。用法: SynTime.DoIt()
return
*/
Class SynTime
{
	DoIt() { ; 成功返回 1
		return this.SetLocalTime( this.BeijingTime() )
	}
	SetLocalTime(YYYYMMDDHHMISS) {
		FormatTime, t, %YYYYMMDDHHMISS%, yyyy/M/1/d/H/m/s/0
		VarSetCapacity(SystemTime, 16, 0)
		Loop, Parse, t, /
			NumPut(A_LoopField, SystemTime, (A_Index-1)*2, "UShort")
		return DllCall("SetLocalTime", "Ptr", &SystemTime)
	}
	BeijingTime() { ; 返回 YYYYMMDDHHMISS
		whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
		whr.Open("HEAD", "http://baidu.com", true)
		whr.Send()
		whr.WaitForResponse()
		_date := whr.GetResponseHeader("Date") ; 示例数据: Mon, 21 Apr 2014 14:58:23 GMT
		arr := StrSplit( _date, [A_Space, ":"] )
		oMonth := {Jan:"01",Feb:"02",Mar:"03",Apr:"04",May:"05",Jun:"06",Jul:"07",Aug:"08",Sep:"09",Oct:"10",Nov:"11",Dec:"12"}
		Mon    := oMonth[ arr.3 ] ; 月份英文缩写转换成数字
		timestamp := arr.4 Mon arr.2 arr.5 arr.6 arr.7 ; YYYYMMDDHHMISS 格式的日期
		p2:=1                             ;- ( UTC + 1 / CET - Central European Time - begin last sunday in octobre / e.g  sun 2018-10-28 03:00>02:00 )
        stringmid,q,timestamp,1,8
        stringmid,Y,timestamp,1,4
        q:=(q)
        lsm := LastSunday(Y . "03")
        lso := LastSunday(Y . "10")
        if (q >= lsm) and (q < lso)
           {
		   DST:="CEST summertime UTC+2"
           p2:=(P2+1)                     ;- ( UTC + 2 / CEST - Central European SUMMER Time - DST begin last sunday in mars / e.g. sun 2018-03-25 02:00>03:00 )
           timestamp += +P2,hours
           }
        else
		   {
		   DST:="CET normaltime UTC+1"
           timestamp += +P2,hours
		   }
		;timestamp += 8, Hours ; 加 8 小时就是北京时间
		return timestamp
	}
}
;-----------------------------------------------------------------------
;- Function last sunday in mars and october for DST daylight saving time in Europe
;- https://autohotkey.com/board/topic/97664-find-specific-wday/ ---
LastSunday(Date)
    {
    Date += 31, D
    Date := SubStr(Date, 1, 6)
    Date += -1, Day
    FormatTime, WD , %Date%, WDay
    Date += -(WD - 1), D
    return, SubStr(Date, 1, 8)
   }
;============================================================================
)
fileappend,%e5x%,%f31%
}
return
;================== END script =========================================

Last edited by garry on 05 Dec 2018, 12:36, edited 1 time in total.
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 05:48

garry wrote: kann ich den einfachen script von 'just me' verwenden um die Computer-Zeit zu setzen ? ( DllCall("SetLocalTime", "Ptr", &SystemTime) )
Hi garry,

ich verstehe nicht, was Du damit meinst. Wenn Du die genaue lokale Zeit hast und die für den Rechner setzen willst, solltest Du Folgendes beachten:
SetLocalTime:

The system uses UTC internally. Therefore, when you call SetLocalTime, the system uses the current time zone information to perform the conversion, including the daylight saving time setting. Note that the system uses the daylight saving time setting of the current time, not the new time you are setting. Therefore, to ensure the correct result, call SetLocalTime a second time, now that the first call has updated the daylight saving time setting.
garry
Posts: 3720
Joined: 22 Dec 2013, 12:50

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 05:57

@just me , danke für Info und Function > display = Sommerzeit / Normalzeit
müsste mal lernen wie man API anwenden kann ...
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 09:11

Hallo garry,

meinst Du das so?

Code: Select all

SetLocalTime(Year, Month, Day, Hour, Minute, Second := 0) {
   ; docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-setlocaltime
   ; SYSTEMTIME -> msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
   VarSetCapacity(SYSTEMTIME, 16, 0)
   NumPut(Year,   SYSTEMTIME,  0, "UShort")
   NumPut(Month,  SYSTEMTIME,  2, "UShort")
   NumPut(Day,    SYSTEMTIME,  6, "UShort")
   NumPut(Hour,   SYSTEMTIME,  8, "UShort")
   NumPut(Minute, SYSTEMTIME, 10, "UShort")
   NumPut(Second, SYSTEMTIME, 12, "UShort")
   ; It's recommended to call the function twice
   If DllCall("SetLocalTime", "Ptr", &SYSTEMTIME, "UInt")
      Return DllCall("SetLocalTime", "Ptr", &SYSTEMTIME, "UInt")
   Return False
}

Die merkwürdigen Ergebnisse beim Setzen von Zeiten, über die Lucky Joe berichtet, halte ich inzwischen für einen AHK Bug. Die Umrechnung von lokaler Zeit in Systemzeit (UTC) muss die Anwendung selbst bewältigen. AHK nutzt hier meiner Meinung nach alte bzw. veraltete Funktionen.
User avatar
LuckyJoe
Posts: 335
Joined: 02 Oct 2013, 09:52

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 10:01

... ich habe mittlerweile auch andere Stimmen zu FileSetTime gelesen, z.B. hier: https://autohotkey.com/board/topic/6814 ... 7-machine/. Von daher schließe ich mich mal der Meinung von justme an, dass es sich um einen Bug innerhalb von AHK handelt. Es macht meiner Meinung nach auch keinen Sinn, dass die Funktion nach Sommer-/Winterzeit unterscheidet, um ein Datei-Datum zu ändern.

Dann bliebe noch meine bescheidene Frage: wie läßt sich das Dateidatum alternativ per DllCall (SystemTimeToFileTime oder so was Ähnlichem) setzen?
Am besten noch wie bei FileSetTime mit
M = Zeitpunkt der letzten Änderung
C = Zeitpunkt der Erstellung
A = Zeitpunkt des letzten Zugriffs

Danke vorab an die Profis.
HG - Lucky Joe
Herzliche Grüße aus dem Rheinland
Lucky Joe
garry
Posts: 3720
Joined: 22 Dec 2013, 12:50

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 12:34

@just me , danke , jetzt bin ich zu blöd um die Funktion zu benützen
mal start als admin ...

Code: Select all

#warn
setworkingdir,%a_scriptdir%
if !A_IsAdmin {
    try
	Run *RunAs "%A_ScriptFullPath%"
	ExitApp
}

;---
;---
User avatar
LuckyJoe
Posts: 335
Joined: 02 Oct 2013, 09:52

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 13:08

Hi garry,

probier das mal (Vorsicht mit der manuell eingegebenen Zeit - wirkt sich ggf. auf Programme/Prozesse im PC aus!):

Code: Select all

#SingleInstance ignore
#NoEnv

if(!A_IsAdmin){
	Run *RunAs "%A_ScriptFullPath%",, UseErrorLevel
	If(ErrorLevel){
		MsgBox, 53, Administatorrechte benötigt
	IfMsgBox, Retry
		Reload
	Else
		ExitApp
	}
	Return
}
;   SetLocalTime(Year, Month, Day, Hour, Minute, Second := 0)
If (SetLocalTime(2018, 12,    05,  18,   55,     00))
	MsgBox, Computerzeit erfolgreich angepasst
Else
	MsgBox, Fehler! - Computerzeit nicht angepasst

ExitApp

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SetLocalTime(Year, Month, Day, Hour, Minute, Second := 0) {
	; docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-setlocaltime
	; SYSTEMTIME -> msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
	VarSetCapacity(SYSTEMTIME, 16, 0)
	NumPut(Year,   SYSTEMTIME,  0, "UShort")
	NumPut(Month,  SYSTEMTIME,  2, "UShort")
	NumPut(Day,    SYSTEMTIME,  6, "UShort")
	NumPut(Hour,   SYSTEMTIME,  8, "UShort")
	NumPut(Minute, SYSTEMTIME, 10, "UShort")
	NumPut(Second, SYSTEMTIME, 12, "UShort")
	; It's recommended to call the function twice
	If DllCall("SetLocalTime", "Ptr", &SYSTEMTIME, "UInt")
		Return DllCall("SetLocalTime", "Ptr", &SYSTEMTIME, "UInt")
	Return False
}
Viel Erfolg!
HG - Lucky Joe
Herzliche Grüße aus dem Rheinland
Lucky Joe
garry
Posts: 3720
Joined: 22 Dec 2013, 12:50

Re: FileSetTime: Sommer-/Winterzeit?

05 Dec 2018, 13:51

@LuckyJoe , vielen Dank , bin auch 'LuckyGarry' , kann jetzt Funktion benützen , danke auch an 'just me' für den script
die Zeit ( oder Datum ) hatte ich vorher so eingestellt ( und mit tmplinshi's Time Sync kann man wieder grad richtigstellen , statt manuell , war nützlich beim alten Computer dessen Zeit/Datum verloren war beim Einschalten )

Code: Select all

adm:=a_isadmin
if (adm=0)
Gosub, RunAsAdmin1
;-----------
stringmid,h,a_now,9,2
stringmid,m,a_now,11,2
stringmid,s,a_now,13,2
now:=h . "." . m . "." . s
;- Set time
runwait,%comspec% /k date /T&time /T&time
return
;--------------------------------------------------------------------
RunAsAdmin1:
Try
Run, *RunAs "%A_ScriptFullPath%"
Exitapp
Return
;--------------------------------------------------------------------
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FileSetTime: Sommer-/Winterzeit?

06 Dec 2018, 06:17

LuckyJoe wrote: Dann bliebe noch meine bescheidene Frage: wie läßt sich das Dateidatum alternativ per DllCall (SystemTimeToFileTime oder so was Ähnlichem) setzen?
Dafür gibt es die API-Funktion SetFileTime. Wenn man die selbst aufrufen will, muss man allerdings die Zeit(en) selbst von lokaler zu Systemzeit (UTC) umrechnen. Zumindest ab Win Vista gibt es dafür recht zuverlässige Funktionen. Willst Du das mal ausprobieren?
User avatar
LuckyJoe
Posts: 335
Joined: 02 Oct 2013, 09:52

Re: FileSetTime: Sommer-/Winterzeit?

06 Dec 2018, 11:03

Hi justme,

danke, dass du an mich gedacht hast ... - auch wenn du mich zum Arbeiten zwingst ;-)
Ok, ich habe zwischenzeitlich etwas recherchiert und das hier gefunden: https://autohotkey.com/board/topic/9905 ... -attribute. Werde mich dann damit mal in den nächsten Tagen "herumschlagen". Melde mich, wenn ich Hilfe brauche (oder bin ich schon jetzt auf dem falschen Weg?)

HG - Lucky Joe
Herzliche Grüße aus dem Rheinland
Lucky Joe
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FileSetTime: Sommer-/Winterzeit?

06 Dec 2018, 11:18

Hi LuckyJoe,

das Ergebnis Deiner Recherche ist völlig korrekt. Es klammert aber die einzige 'echte' Schwierigkeit aus: Welche Werte müssen in ftCreate, ftAccess und ftModify bei Aufruf der Funktion setFileTimes() übergeben werden, wenn man das jeweilige Datum ändern will? Ich kann gern versuchen, Dich bei der Konvertierung der Zeitformate zu unterstützen.
User avatar
LuckyJoe
Posts: 335
Joined: 02 Oct 2013, 09:52

Re: FileSetTime: Sommer-/Winterzeit?

06 Dec 2018, 13:20

... danke, justme, ich bagger mich da erst einmal alleine durch ... will ja was lernen. Bei Bedarf frage ich gerne noch einmal nach.
Vielleicht schon mal vorweg: kann ich ftCreate und ftAccess weglassen, wenn ich nur ftModify ändern will (also mit SetFileTimes(%file%, , , %ftModify%))?
Herzliche Grüße aus dem Rheinland
Lucky Joe
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: FileSetTime: Sommer-/Winterzeit?

07 Dec 2018, 03:13

Moin,

Microsoft sagt, dass man für jeden der drei Parameter entweder 0 oder die Adresse einer mit Nullen gefüllten FILETIME Struktur übergeben kann, wenn der zugehörige Zeitstempel nicht verändert werden soll.
If the application does not need to change this information, set this parameter either to NULL or to a pointer to a FILETIME structure that has both the dwLowDateTime and dwHighDateTime members set to 0.
Die Funktionsdefinition sollte also so aussehen können:

Code: Select all

setFileTimes(file, ftCreate := 0, ftAccess := 0, ftModify := 0) {
...
}
Die Zeitparameter werden so optional.

Übrigens:
LuckyJoe wrote:... (also mit SetFileTimes(%file%, , , %ftModify%)
Eher nicht! Funktionsaufrufe sind Ausdrücke/Expressions. Variablennamen dürfen deshalb für eine einfache Referenz nicht in %-Zeichen eingeschlossen werden. ;)

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 20 guests