Date.au3 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  1. #include-once
  2. #include "DateTimeConstants.au3"
  3. #include "Memory.au3"
  4. #include "Security.au3"
  5. #include "StructureConstants.au3"
  6. #include "WinAPIError.au3"
  7. #include "WinAPIHObj.au3"
  8. #include "WinAPILocale.au3"
  9. ; #INDEX# =======================================================================================================================
  10. ; Title .........: Date
  11. ; AutoIt Version : 3.3.14.5
  12. ; Language ......: English
  13. ; Description ...: Functions that assist with Date/Time management.
  14. ; There are five time formats: System, File, Local, MS-DOS and Windows. Time related functions return time in
  15. ; one of these formats. You can also use the time functions to convert between time formats for ease of
  16. ; comparison and display
  17. ; Author(s) .....: JdeB, jlandes, exodius, PaulIA, Tuape, SlimShady, GaryFrost, /dev/null, Marc
  18. ; ===============================================================================================================================
  19. ; #NO_DOC_FUNCTION# =============================================================================================================
  20. ; Not working/documented/implemented at this time
  21. ;
  22. ; _DateLastWeekdayNum
  23. ; _DateLastMonthNum
  24. ; _DateLastMonthYear
  25. ; _DateNextWeekdayNum
  26. ; _DateNextMonthNum
  27. ; _DateNextMonthYear
  28. ; _Date_JulianDayNo
  29. ; _JulianToDate
  30. ; _WeekNumber
  31. ; _DaysInMonth
  32. ; ===============================================================================================================================
  33. ; #CURRENT# =====================================================================================================================
  34. ; _DateAdd
  35. ; _DateDayOfWeek
  36. ; _DateDaysInMonth
  37. ; _DateDiff
  38. ; _DateIsLeapYear
  39. ; _DateIsValid
  40. ; _DateTimeFormat
  41. ; _DateTimeSplit
  42. ; _DateToDayOfWeek
  43. ; _DateToDayOfWeekISO
  44. ; _DateToDayValue
  45. ; _DateToMonth
  46. ; _DayValueToDate
  47. ; _Now
  48. ; _NowCalc
  49. ; _NowCalcDate
  50. ; _NowDate
  51. ; _NowTime
  52. ; _SetDate
  53. ; _SetTime
  54. ; _TicksToTime
  55. ; _TimeToTicks
  56. ; _WeekNumberISO
  57. ; _Date_Time_CompareFileTime
  58. ; _Date_Time_DOSDateTimeToFileTime
  59. ; _Date_Time_DOSDateToArray
  60. ; _Date_Time_DOSDateTimeToArray
  61. ; _Date_Time_DOSDateTimeToStr
  62. ; _Date_Time_DOSDateToStr
  63. ; _Date_Time_DOSTimeToArray
  64. ; _Date_Time_DOSTimeToStr
  65. ; _Date_Time_EncodeFileTime
  66. ; _Date_Time_EncodeSystemTime
  67. ; _Date_Time_FileTimeToArray
  68. ; _Date_Time_FileTimeToStr
  69. ; _Date_Time_FileTimeToDOSDateTime
  70. ; _Date_Time_FileTimeToLocalFileTime
  71. ; _Date_Time_FileTimeToSystemTime
  72. ; _Date_Time_GetFileTime
  73. ; _Date_Time_GetLocalTime
  74. ; _Date_Time_GetSystemTime
  75. ; _Date_Time_GetSystemTimeAdjustment
  76. ; _Date_Time_GetSystemTimeAsFileTime
  77. ; _Date_Time_GetSystemTimes
  78. ; _Date_Time_GetTickCount
  79. ; _Date_Time_GetTimeZoneInformation
  80. ; _Date_Time_LocalFileTimeToFileTime
  81. ; _Date_Time_SetFileTime
  82. ; _Date_Time_SetLocalTime
  83. ; _Date_Time_SetSystemTime
  84. ; _Date_Time_SetSystemTimeAdjustment
  85. ; _Date_Time_SetTimeZoneInformation
  86. ; _Date_Time_SystemTimeToArray
  87. ; _Date_Time_SystemTimeToDateStr
  88. ; _Date_Time_SystemTimeToDateTimeStr
  89. ; _Date_Time_SystemTimeToFileTime
  90. ; _Date_Time_SystemTimeToTimeStr
  91. ; _Date_Time_SystemTimeToTzSpecificLocalTime
  92. ; _Date_Time_TzSpecificLocalTimeToSystemTime
  93. ; ===============================================================================================================================
  94. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  95. ; __DateIsMonth
  96. ; __DateIsYear
  97. ; __Date_Time_CloneSystemTime
  98. ; ===============================================================================================================================
  99. ; #FUNCTION# ====================================================================================================================
  100. ; Author ........: Jos van der Zande
  101. ; Modified.......:
  102. ; ===============================================================================================================================
  103. Func _DateAdd($sType, $iNumber, $sDate)
  104. Local $asTimePart[4]
  105. Local $asDatePart[4]
  106. Local $iJulianDate
  107. ; Verify that $sType is Valid
  108. $sType = StringLeft($sType, 1)
  109. If StringInStr("D,M,Y,w,h,n,s", $sType) = 0 Or $sType = "" Then
  110. Return SetError(1, 0, 0)
  111. EndIf
  112. ; Verify that Value to Add is Valid
  113. If Not StringIsInt($iNumber) Then
  114. Return SetError(2, 0, 0)
  115. EndIf
  116. ; Verify If InputDate is valid
  117. If Not _DateIsValid($sDate) Then
  118. Return SetError(3, 0, 0)
  119. EndIf
  120. ; split the date and time into arrays
  121. _DateTimeSplit($sDate, $asDatePart, $asTimePart)
  122. ; ====================================================
  123. ; adding days then get the julian date
  124. ; add the number of day
  125. ; and convert back to Gregorian
  126. If $sType = "d" Or $sType = "w" Then
  127. If $sType = "w" Then $iNumber = $iNumber * 7
  128. $iJulianDate = _DateToDayValue($asDatePart[1], $asDatePart[2], $asDatePart[3]) + $iNumber
  129. _DayValueToDate($iJulianDate, $asDatePart[1], $asDatePart[2], $asDatePart[3])
  130. EndIf
  131. ; ====================================================
  132. ; adding Months
  133. If $sType = "m" Then
  134. $asDatePart[2] = $asDatePart[2] + $iNumber
  135. ; pos number of months
  136. While $asDatePart[2] > 12
  137. $asDatePart[2] = $asDatePart[2] - 12
  138. $asDatePart[1] = $asDatePart[1] + 1
  139. WEnd
  140. ; Neg number of months
  141. While $asDatePart[2] < 1
  142. $asDatePart[2] = $asDatePart[2] + 12
  143. $asDatePart[1] = $asDatePart[1] - 1
  144. WEnd
  145. EndIf
  146. ; ====================================================
  147. ; adding Years
  148. If $sType = "y" Then
  149. $asDatePart[1] = $asDatePart[1] + $iNumber
  150. EndIf
  151. ; ====================================================
  152. ; adding Time value
  153. If $sType = "h" Or $sType = "n" Or $sType = "s" Then
  154. Local $iTimeVal = _TimeToTicks($asTimePart[1], $asTimePart[2], $asTimePart[3]) / 1000
  155. If $sType = "h" Then $iTimeVal = $iTimeVal + $iNumber * 3600
  156. If $sType = "n" Then $iTimeVal = $iTimeVal + $iNumber * 60
  157. If $sType = "s" Then $iTimeVal = $iTimeVal + $iNumber
  158. ; calculated days to add
  159. Local $iDay2Add = Int($iTimeVal / (24 * 60 * 60))
  160. $iTimeVal = $iTimeVal - $iDay2Add * 24 * 60 * 60
  161. If $iTimeVal < 0 Then
  162. $iDay2Add = $iDay2Add - 1
  163. $iTimeVal = $iTimeVal + 24 * 60 * 60
  164. EndIf
  165. $iJulianDate = _DateToDayValue($asDatePart[1], $asDatePart[2], $asDatePart[3]) + $iDay2Add
  166. ; calculate the julian back to date
  167. _DayValueToDate($iJulianDate, $asDatePart[1], $asDatePart[2], $asDatePart[3])
  168. ; caluculate the new time
  169. _TicksToTime($iTimeVal * 1000, $asTimePart[1], $asTimePart[2], $asTimePart[3])
  170. EndIf
  171. ; ====================================================
  172. ; check if the Input day is Greater then the new month last day.
  173. ; if so then change it to the last possible day in the month
  174. Local $iNumDays = _DaysInMonth($asDatePart[1])
  175. ;
  176. If $iNumDays[$asDatePart[2]] < $asDatePart[3] Then $asDatePart[3] = $iNumDays[$asDatePart[2]]
  177. ; ========================
  178. ; Format the return date
  179. $sDate = $asDatePart[1] & '/' & StringRight("0" & $asDatePart[2], 2) & '/' & StringRight("0" & $asDatePart[3], 2)
  180. ; add the time when specified in the input
  181. If $asTimePart[0] > 0 Then
  182. If $asTimePart[0] > 2 Then
  183. $sDate = $sDate & " " & StringRight("0" & $asTimePart[1], 2) & ':' & StringRight("0" & $asTimePart[2], 2) & ':' & StringRight("0" & $asTimePart[3], 2)
  184. Else
  185. $sDate = $sDate & " " & StringRight("0" & $asTimePart[1], 2) & ':' & StringRight("0" & $asTimePart[2], 2)
  186. EndIf
  187. EndIf
  188. ;
  189. Return $sDate
  190. EndFunc ;==>_DateAdd
  191. ; #FUNCTION# ====================================================================================================================
  192. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  193. ; Modified.......: trancexx
  194. ; ===============================================================================================================================
  195. Func _DateDayOfWeek($iDayNum, $iFormat = Default)
  196. Local Const $MONDAY_IS_NO1 = 128 ; Undocumented - If someone passes $iFormat with 128, Monday will be regarded as the first day of the week and not Sunday.
  197. If $iFormat = Default Then $iFormat = 0
  198. $iDayNum = Int($iDayNum)
  199. If $iDayNum < 1 Or $iDayNum > 7 Then Return SetError(1, 0, "")
  200. Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
  201. DllStructSetData($tSYSTEMTIME, "Year", BitAND($iFormat, $MONDAY_IS_NO1) ? 2007 : 2006) ; 2006 = Sunday 1st Jan or 2007 = Monday 1st Jan.
  202. DllStructSetData($tSYSTEMTIME, "Month", 1)
  203. DllStructSetData($tSYSTEMTIME, "Day", $iDayNum)
  204. Return _WinAPI_GetDateFormat(BitAND($iFormat, $DMW_LOCALE_LONGNAME) ? $LOCALE_USER_DEFAULT : $LOCALE_INVARIANT, $tSYSTEMTIME, 0, BitAND($iFormat, $DMW_SHORTNAME) ? "ddd" : "dddd")
  205. EndFunc ;==>_DateDayOfWeek
  206. ; #FUNCTION# ====================================================================================================================
  207. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  208. ; Modified.......:
  209. ; ===============================================================================================================================
  210. Func _DateDaysInMonth($iYear, $iMonthNum)
  211. $iMonthNum = Int($iMonthNum)
  212. $iYear = Int($iYear)
  213. Return __DateIsMonth($iMonthNum) And __DateIsYear($iYear) ? _DaysInMonth($iYear)[$iMonthNum] : SetError(1, 0, 0)
  214. EndFunc ;==>_DateDaysInMonth
  215. ; #FUNCTION# ====================================================================================================================
  216. ; Author ........: Jos van der Zande
  217. ; Modified.......:
  218. ; ===============================================================================================================================
  219. Func _DateDiff($sType, $sStartDate, $sEndDate)
  220. ; Verify that $sType is Valid
  221. $sType = StringLeft($sType, 1)
  222. If StringInStr("d,m,y,w,h,n,s", $sType) = 0 Or $sType = "" Then
  223. Return SetError(1, 0, 0)
  224. EndIf
  225. ; Verify If StartDate is valid
  226. If Not _DateIsValid($sStartDate) Then
  227. Return SetError(2, 0, 0)
  228. EndIf
  229. ; Verify If EndDate is valid
  230. If Not _DateIsValid($sEndDate) Then
  231. Return SetError(3, 0, 0)
  232. EndIf
  233. Local $asStartDatePart[4], $asStartTimePart[4], $asEndDatePart[4], $asEndTimePart[4]
  234. ; split the StartDate and Time into arrays
  235. _DateTimeSplit($sStartDate, $asStartDatePart, $asStartTimePart)
  236. ; split the End Date and time into arrays
  237. _DateTimeSplit($sEndDate, $asEndDatePart, $asEndTimePart)
  238. ; ====================================================
  239. ; Get the differens in days between the 2 dates
  240. Local $aDaysDiff = _DateToDayValue($asEndDatePart[1], $asEndDatePart[2], $asEndDatePart[3]) - _DateToDayValue($asStartDatePart[1], $asStartDatePart[2], $asStartDatePart[3])
  241. ; ====================================================
  242. Local $iTimeDiff, $iYearDiff, $iStartTimeInSecs, $iEndTimeInSecs
  243. ; Get the differens in Seconds between the 2 times when specified
  244. If $asStartTimePart[0] > 1 And $asEndTimePart[0] > 1 Then
  245. $iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3]
  246. $iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3]
  247. $iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
  248. If $iTimeDiff < 0 Then
  249. $aDaysDiff = $aDaysDiff - 1
  250. $iTimeDiff = $iTimeDiff + 24 * 60 * 60
  251. EndIf
  252. Else
  253. $iTimeDiff = 0
  254. EndIf
  255. Select
  256. Case $sType = "d"
  257. Return $aDaysDiff
  258. Case $sType = "m"
  259. $iYearDiff = $asEndDatePart[1] - $asStartDatePart[1]
  260. Local $iMonthDiff = $asEndDatePart[2] - $asStartDatePart[2] + $iYearDiff * 12
  261. If $asEndDatePart[3] < $asStartDatePart[3] Then $iMonthDiff = $iMonthDiff - 1
  262. $iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3]
  263. $iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3]
  264. $iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
  265. If $asEndDatePart[3] = $asStartDatePart[3] And $iTimeDiff < 0 Then $iMonthDiff = $iMonthDiff - 1
  266. Return $iMonthDiff
  267. Case $sType = "y"
  268. $iYearDiff = $asEndDatePart[1] - $asStartDatePart[1]
  269. If $asEndDatePart[2] < $asStartDatePart[2] Then $iYearDiff = $iYearDiff - 1
  270. If $asEndDatePart[2] = $asStartDatePart[2] And $asEndDatePart[3] < $asStartDatePart[3] Then $iYearDiff = $iYearDiff - 1
  271. $iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3]
  272. $iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3]
  273. $iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
  274. If $asEndDatePart[2] = $asStartDatePart[2] And $asEndDatePart[3] = $asStartDatePart[3] And $iTimeDiff < 0 Then $iYearDiff = $iYearDiff - 1
  275. Return $iYearDiff
  276. Case $sType = "w"
  277. Return Int($aDaysDiff / 7)
  278. Case $sType = "h"
  279. Return $aDaysDiff * 24 + Int($iTimeDiff / 3600)
  280. Case $sType = "n"
  281. Return $aDaysDiff * 24 * 60 + Int($iTimeDiff / 60)
  282. Case $sType = "s"
  283. Return $aDaysDiff * 24 * 60 * 60 + $iTimeDiff
  284. EndSelect
  285. EndFunc ;==>_DateDiff
  286. ; #FUNCTION# ====================================================================================================================
  287. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  288. ; Modified.......:
  289. ; ===============================================================================================================================
  290. Func _DateIsLeapYear($iYear)
  291. If StringIsInt($iYear) Then
  292. Select
  293. Case Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0
  294. Return 1
  295. Case Mod($iYear, 400) = 0
  296. Return 1
  297. Case Else
  298. Return 0
  299. EndSelect
  300. EndIf
  301. Return SetError(1, 0, 0)
  302. EndFunc ;==>_DateIsLeapYear
  303. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  304. ; Name...........: __DateIsMonth
  305. ; Description ...: Checks a given number to see if it is a valid month.
  306. ; Syntax.........: __DateIsMonth ( $iNumber )
  307. ; Parameters ....: $iNumber - Month number to check.
  308. ; Return values .: Success - Returns 1 if month is valid.
  309. ; Failure - Returns 0
  310. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  311. ; Modified.......:
  312. ; Remarks .......:
  313. ; Related .......:
  314. ; Link ..........:
  315. ; Example .......:
  316. ; ===============================================================================================================================
  317. Func __DateIsMonth($iNumber)
  318. $iNumber = Int($iNumber)
  319. Return $iNumber >= 1 And $iNumber <= 12
  320. EndFunc ;==>__DateIsMonth
  321. ; #FUNCTION# ====================================================================================================================
  322. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  323. ; Modified.......:
  324. ; ===============================================================================================================================
  325. Func _DateIsValid($sDate)
  326. Local $asDatePart[4], $asTimePart[4]
  327. #cs
  328. A regular expression to verify the date and time string.
  329. $bIsDate = Not StringRegExp($sDate, '[^\d.\-/:]')
  330. $bIsDate = StringRegExp($sDate, '(?x)^\d{4}(?:[.\-/]\d{2}){2} (?: (?:T|\h)\d{2}:\d{2} (?::\d{2})? )?$') > 0
  331. #ce
  332. _DateTimeSplit($sDate, $asDatePart, $asTimePart)
  333. ; verify valid input date values
  334. If Not StringIsInt($asDatePart[1]) Then Return 0
  335. If Not StringIsInt($asDatePart[2]) Then Return 0
  336. If Not StringIsInt($asDatePart[3]) Then Return 0
  337. ; Make sure the Date parts contains numeric
  338. $asDatePart[1] = Int($asDatePart[1])
  339. $asDatePart[2] = Int($asDatePart[2])
  340. $asDatePart[3] = Int($asDatePart[3])
  341. ; check if all contain valid values
  342. Local $iNumDays = _DaysInMonth($asDatePart[1])
  343. If $asDatePart[1] < 1000 Or $asDatePart[1] > 2999 Then Return 0
  344. If $asDatePart[2] < 1 Or $asDatePart[2] > 12 Then Return 0
  345. If $asDatePart[3] < 1 Or $asDatePart[3] > $iNumDays[$asDatePart[2]] Then Return 0
  346. ; check Time portion
  347. If $asTimePart[0] < 1 Then Return 1 ; No time specified so date must be correct
  348. If $asTimePart[0] < 2 Then Return 0 ; need at least HH:MM when something is specified
  349. If $asTimePart[0] = 2 Then $asTimePart[3] = "00" ; init SS when only HH:MM is specified
  350. ; Make sure the Time parts contains numeric
  351. If Not StringIsInt($asTimePart[1]) Then Return 0
  352. If Not StringIsInt($asTimePart[2]) Then Return 0
  353. If Not StringIsInt($asTimePart[3]) Then Return 0
  354. ; check if all contain valid values
  355. $asTimePart[1] = Int($asTimePart[1])
  356. $asTimePart[2] = Int($asTimePart[2])
  357. $asTimePart[3] = Int($asTimePart[3])
  358. If $asTimePart[1] < 0 Or $asTimePart[1] > 23 Then Return 0
  359. If $asTimePart[2] < 0 Or $asTimePart[2] > 59 Then Return 0
  360. If $asTimePart[3] < 0 Or $asTimePart[3] > 59 Then Return 0
  361. ; we got here so date/time must be good
  362. Return 1
  363. EndFunc ;==>_DateIsValid
  364. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  365. ; Name...........: __DateIsYear
  366. ; Description ...: Checks a given number to see if it is a valid year.
  367. ; Syntax.........: __DateIsYear ( $iNumber )
  368. ; Parameters ....: $iNumber - Year number to check.
  369. ; Return values .: Success - Returns 1 if year is valid.
  370. ; Failure - Returns 0
  371. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  372. ; Modified.......:
  373. ; Remarks .......:
  374. ; Related .......:
  375. ; Link ..........:
  376. ; Example .......:
  377. ; ===============================================================================================================================
  378. Func __DateIsYear($iNumber)
  379. Return StringLen($iNumber) = 4
  380. EndFunc ;==>__DateIsYear
  381. ; #NO_DOC_FUNCTION# =============================================================================================================
  382. ; Name...........: _DateLastWeekdayNum
  383. ; Description ...: Returns previous weekday number, based on the specified day of the week.
  384. ; Syntax.........: _DateLastWeekdayNum ( $iWeekdayNum )
  385. ; Parameters ....: $iWeekdayNum - Weekday number
  386. ; Return values .: Success - Previous weekday number
  387. ; Failure - Returns 0 and sets @error = 1
  388. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  389. ; Modified.......:
  390. ; Remarks .......:
  391. ; Related .......:
  392. ; Link ..........:
  393. ; Example .......:
  394. ; ===============================================================================================================================
  395. Func _DateLastWeekdayNum($iWeekdayNum)
  396. Select
  397. Case Not StringIsInt($iWeekdayNum)
  398. Return SetError(1, 0, 0)
  399. Case $iWeekdayNum < 1 Or $iWeekdayNum > 7
  400. Return SetError(2, 0, 0)
  401. Case Else
  402. Local $iLastWeekdayNum
  403. If $iWeekdayNum = 1 Then
  404. $iLastWeekdayNum = 7
  405. Else
  406. $iLastWeekdayNum = $iWeekdayNum - 1
  407. EndIf
  408. Return $iLastWeekdayNum
  409. EndSelect
  410. EndFunc ;==>_DateLastWeekdayNum
  411. ; #NO_DOC_FUNCTION# =============================================================================================================
  412. ; Name...........: _DateLastMonthNum
  413. ; Description ...: Returns previous month number, based on the specified month.
  414. ; Syntax.........: _DateLastMonthNum ( $iMonthNum )
  415. ; Parameters ....: $iMonthNum - Month number
  416. ; Return values .: Success - Previous month number
  417. ; Failure - Returns 0 and sets @error = 1
  418. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  419. ; Modified.......:
  420. ; Remarks .......:
  421. ; Related .......:
  422. ; Link ..........:
  423. ; Example .......:
  424. ; ===============================================================================================================================
  425. Func _DateLastMonthNum($iMonthNum)
  426. Select
  427. Case Not StringIsInt($iMonthNum)
  428. Return SetError(1, 0, 0)
  429. Case Not __DateIsMonth($iMonthNum)
  430. Return SetError(2, 0, 0)
  431. Case Else
  432. Local $iLastMonthNum
  433. If $iMonthNum = 1 Then
  434. $iLastMonthNum = 12
  435. Else
  436. $iLastMonthNum = $iMonthNum - 1
  437. EndIf
  438. $iLastMonthNum = StringFormat("%02d", $iLastMonthNum)
  439. Return $iLastMonthNum
  440. EndSelect
  441. EndFunc ;==>_DateLastMonthNum
  442. ; #NO_DOC_FUNCTION# =============================================================================================================
  443. ; Name...........: _DateLastMonthYear
  444. ; Description ...: Returns previous month's year, based on the specified month and year.
  445. ; Syntax.........: _DateLastMonthYear ( $iMonthNum, $iYear )
  446. ; Parameters ....: $iMonthNum - Month number
  447. ; $iYear - Year
  448. ; Return values .: Success - Previous month's year
  449. ; Failure - Returns 0 and sets @error = 1
  450. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  451. ; Modified.......:
  452. ; Remarks .......:
  453. ; Related .......:
  454. ; Link ..........:
  455. ; Example .......:
  456. ; ===============================================================================================================================
  457. Func _DateLastMonthYear($iMonthNum, $iYear)
  458. Select
  459. Case Not StringIsInt($iMonthNum) Or Not StringIsInt($iYear)
  460. Return SetError(1, 0, 0)
  461. Case Not __DateIsMonth($iMonthNum)
  462. Return SetError(2, 0, 0)
  463. Case Else
  464. Local $iLastYear
  465. If $iMonthNum = 1 Then
  466. $iLastYear = $iYear - 1
  467. Else
  468. $iLastYear = $iYear
  469. EndIf
  470. $iLastYear = StringFormat("%04d", $iLastYear)
  471. Return $iLastYear
  472. EndSelect
  473. EndFunc ;==>_DateLastMonthYear
  474. ; #NO_DOC_FUNCTION# =============================================================================================================
  475. ; Name...........: _DateNextWeekdayNum
  476. ; Description ...: Returns next weekday number, based on the specified day of the week.
  477. ; Syntax.........: _DateNextWeekdayNum ( $iWeekdayNum )
  478. ; Parameters ....: $iWeekdayNum - Weekday number
  479. ; Return values .: Success - Next weekday number
  480. ; Failure - 0 and sets @error = 1
  481. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  482. ; Modified.......:
  483. ; Remarks .......:
  484. ; Related .......:
  485. ; Link ..........:
  486. ; Example .......:
  487. ; ===============================================================================================================================
  488. Func _DateNextWeekdayNum($iWeekdayNum)
  489. Select
  490. Case Not StringIsInt($iWeekdayNum)
  491. Return SetError(1, 0, 0)
  492. Case $iWeekdayNum < 1 Or $iWeekdayNum > 7
  493. Return SetError(2, 0, 0)
  494. Case Else
  495. Local $iNextWeekdayNum
  496. If $iWeekdayNum = 7 Then
  497. $iNextWeekdayNum = 1
  498. Else
  499. $iNextWeekdayNum = $iWeekdayNum + 1
  500. EndIf
  501. Return $iNextWeekdayNum
  502. EndSelect
  503. EndFunc ;==>_DateNextWeekdayNum
  504. ; #NO_DOC_FUNCTION# =============================================================================================================
  505. ; Name...........: _DateNextMonthNum
  506. ; Description ...: Returns next month number, based on the specified month.
  507. ; Syntax.........: _DateNextMonthNum ( $iMonthNum )
  508. ; Parameters ....: $iMonthNum - Month number
  509. ; Return values .: Success - Next month number
  510. ; Failure - 0 and sets @error = 1
  511. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  512. ; Modified.......:
  513. ; Remarks .......:
  514. ; Related .......:
  515. ; Link ..........:
  516. ; Example .......:
  517. ; ===============================================================================================================================
  518. Func _DateNextMonthNum($iMonthNum)
  519. Select
  520. Case Not StringIsInt($iMonthNum)
  521. Return SetError(1, 0, 0)
  522. Case Not __DateIsMonth($iMonthNum)
  523. Return SetError(2, 0, 0)
  524. Case Else
  525. Local $iNextMonthNum
  526. If $iMonthNum = 12 Then
  527. $iNextMonthNum = 1
  528. Else
  529. $iNextMonthNum = $iMonthNum + 1
  530. EndIf
  531. $iNextMonthNum = StringFormat("%02d", $iNextMonthNum)
  532. Return $iNextMonthNum
  533. EndSelect
  534. EndFunc ;==>_DateNextMonthNum
  535. ; #NO_DOC_FUNCTION# =============================================================================================================
  536. ; Name...........: _DateNextMonthYear
  537. ; Description ...: Returns next month's year, based on the specified month and year.
  538. ; Syntax.........: _DateNextMonthYear ( $iMonthNum, $iYear )
  539. ; Parameters ....: $iMonthNum - Month number
  540. ; $iYear - Year
  541. ; Return values .: Success - Next month's year
  542. ; Failure - 0 and sets @error = 1
  543. ; Author ........: Jeremy Landes <jlandes at landeserve dot com>
  544. ; Modified.......:
  545. ; Remarks .......:
  546. ; Related .......:
  547. ; Link ..........:
  548. ; Example .......:
  549. ; ===============================================================================================================================
  550. Func _DateNextMonthYear($iMonthNum, $iYear)
  551. Select
  552. Case Not StringIsInt($iMonthNum) Or Not StringIsInt($iYear)
  553. Return SetError(1, 0, 0)
  554. Case Not __DateIsMonth($iMonthNum)
  555. Return SetError(2, 0, 0)
  556. Case Else
  557. Local $iNextYear
  558. If $iMonthNum = 12 Then
  559. $iNextYear = $iYear + 1
  560. Else
  561. $iNextYear = $iYear
  562. EndIf
  563. $iNextYear = StringFormat("%04d", $iNextYear)
  564. Return $iNextYear
  565. EndSelect
  566. EndFunc ;==>_DateNextMonthYear
  567. ; #FUNCTION# ====================================================================================================================
  568. ; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
  569. ; Modified.......:
  570. ; ===============================================================================================================================
  571. Func _DateTimeFormat($sDate, $sType)
  572. Local $asDatePart[4], $asTimePart[4]
  573. Local $sTempDate = "", $sTempTime = ""
  574. Local $sAM, $sPM, $sTempString = ""
  575. ; Verify If InputDate is valid
  576. If Not _DateIsValid($sDate) Then
  577. Return SetError(1, 0, "")
  578. EndIf
  579. ; input validation
  580. If $sType < 0 Or $sType > 5 Or Not IsInt($sType) Then
  581. Return SetError(2, 0, "")
  582. EndIf
  583. ; split the date and time into arrays
  584. _DateTimeSplit($sDate, $asDatePart, $asTimePart)
  585. Switch $sType
  586. Case 0
  587. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SSHORTDATE) ; Get short date format.
  588. If Not @error And Not ($sTempString = '') Then
  589. $sTempDate = $sTempString
  590. Else
  591. $sTempDate = "M/d/yyyy"
  592. EndIf
  593. If $asTimePart[0] > 1 Then
  594. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_STIMEFORMAT) ; Get short time format.
  595. If Not @error And Not ($sTempString = '') Then
  596. $sTempTime = $sTempString
  597. Else
  598. $sTempTime = "h:mm:ss tt"
  599. EndIf
  600. EndIf
  601. Case 1
  602. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SLONGDATE) ; Get long date format.
  603. If Not @error And Not ($sTempString = '') Then
  604. $sTempDate = $sTempString
  605. Else
  606. $sTempDate = "dddd, MMMM dd, yyyy"
  607. EndIf
  608. Case 2
  609. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SSHORTDATE) ; Get short date format.
  610. If Not @error And Not ($sTempString = '') Then
  611. $sTempDate = $sTempString
  612. Else
  613. $sTempDate = "M/d/yyyy"
  614. EndIf
  615. Case 3
  616. If $asTimePart[0] > 1 Then
  617. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_STIMEFORMAT) ; Get short time format.
  618. If Not @error And Not ($sTempString = '') Then
  619. $sTempTime = $sTempString
  620. Else
  621. $sTempTime = "h:mm:ss tt"
  622. EndIf
  623. EndIf
  624. Case 4
  625. If $asTimePart[0] > 1 Then
  626. $sTempTime = "hh:mm"
  627. EndIf
  628. Case 5
  629. If $asTimePart[0] > 1 Then
  630. $sTempTime = "hh:mm:ss"
  631. EndIf
  632. EndSwitch
  633. ; Format DATE
  634. If $sTempDate <> "" Then
  635. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SDATE) ; Get short date format.
  636. If Not @error And Not ($sTempString = '') Then
  637. $sTempDate = StringReplace($sTempDate, "/", $sTempString)
  638. EndIf
  639. Local $iWday = _DateToDayOfWeek($asDatePart[1], $asDatePart[2], $asDatePart[3])
  640. $asDatePart[3] = StringRight("0" & $asDatePart[3], 2) ; make sure the length is 2
  641. $asDatePart[2] = StringRight("0" & $asDatePart[2], 2) ; make sure the length is 2
  642. $sTempDate = StringReplace($sTempDate, "d", "@")
  643. $sTempDate = StringReplace($sTempDate, "m", "#")
  644. $sTempDate = StringReplace($sTempDate, "y", "&")
  645. $sTempDate = StringReplace($sTempDate, "@@@@", _DateDayOfWeek($iWday, 0))
  646. $sTempDate = StringReplace($sTempDate, "@@@", _DateDayOfWeek($iWday, 1))
  647. $sTempDate = StringReplace($sTempDate, "@@", $asDatePart[3])
  648. $sTempDate = StringReplace($sTempDate, "@", StringReplace(StringLeft($asDatePart[3], 1), "0", "") & StringRight($asDatePart[3], 1))
  649. $sTempDate = StringReplace($sTempDate, "####", _DateToMonth($asDatePart[2], 0))
  650. $sTempDate = StringReplace($sTempDate, "###", _DateToMonth($asDatePart[2], 1))
  651. $sTempDate = StringReplace($sTempDate, "##", $asDatePart[2])
  652. $sTempDate = StringReplace($sTempDate, "#", StringReplace(StringLeft($asDatePart[2], 1), "0", "") & StringRight($asDatePart[2], 1))
  653. $sTempDate = StringReplace($sTempDate, "&&&&", $asDatePart[1])
  654. $sTempDate = StringReplace($sTempDate, "&&", StringRight($asDatePart[1], 2))
  655. EndIf
  656. ; Format TIME
  657. If $sTempTime <> "" Then
  658. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_S1159) ; AM designator.
  659. If Not @error And Not ($sTempString = '') Then
  660. $sAM = $sTempString
  661. Else
  662. $sAM = "AM"
  663. EndIf
  664. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_S2359) ; PM designator.
  665. If Not @error And Not ($sTempString = '') Then
  666. $sPM = $sTempString
  667. Else
  668. $sPM = "PM"
  669. EndIf
  670. $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_STIME) ; Time seperator.
  671. If Not @error And Not ($sTempString = '') Then
  672. $sTempTime = StringReplace($sTempTime, ":", $sTempString)
  673. EndIf
  674. If StringInStr($sTempTime, "tt") Then
  675. If $asTimePart[1] < 12 Then
  676. $sTempTime = StringReplace($sTempTime, "tt", $sAM)
  677. If $asTimePart[1] = 0 Then $asTimePart[1] = 12
  678. Else
  679. $sTempTime = StringReplace($sTempTime, "tt", $sPM)
  680. If $asTimePart[1] > 12 Then $asTimePart[1] = $asTimePart[1] - 12
  681. EndIf
  682. EndIf
  683. $asTimePart[1] = StringRight("0" & $asTimePart[1], 2) ; make sure the length is 2
  684. $asTimePart[2] = StringRight("0" & $asTimePart[2], 2) ; make sure the length is 2
  685. $asTimePart[3] = StringRight("0" & $asTimePart[3], 2) ; make sure the length is 2
  686. $sTempTime = StringReplace($sTempTime, "hh", StringFormat("%02d", $asTimePart[1]))
  687. $sTempTime = StringReplace($sTempTime, "h", StringReplace(StringLeft($asTimePart[1], 1), "0", "") & StringRight($asTimePart[1], 1))
  688. $sTempTime = StringReplace($sTempTime, "mm", StringFormat("%02d", $asTimePart[2]))
  689. $sTempTime = StringReplace($sTempTime, "ss", StringFormat("%02d", $asTimePart[3]))
  690. $sTempDate = StringStripWS($sTempDate & " " & $sTempTime, $STR_STRIPLEADING + $STR_STRIPTRAILING)
  691. EndIf
  692. Return $sTempDate
  693. EndFunc ;==>_DateTimeFormat
  694. ; #FUNCTION# ====================================================================================================================
  695. ; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
  696. ; Modified.......:
  697. ; ===============================================================================================================================
  698. Func _DateTimeSplit($sDate, ByRef $aDatePart, ByRef $iTimePart)
  699. ; split the Date and Time portion
  700. Local $sDateTime = StringSplit($sDate, " T")
  701. ; split the date portion
  702. If $sDateTime[0] > 0 Then $aDatePart = StringSplit($sDateTime[1], "/-.")
  703. ; split the Time portion
  704. If $sDateTime[0] > 1 Then
  705. $iTimePart = StringSplit($sDateTime[2], ":")
  706. If UBound($iTimePart) < 4 Then ReDim $iTimePart[4]
  707. Else
  708. Dim $iTimePart[4]
  709. EndIf
  710. ; Ensure the arrays contain 4 values
  711. If UBound($aDatePart) < 4 Then ReDim $aDatePart[4]
  712. ; update the array to contain numbers not strings
  713. For $x = 1 To 3
  714. If StringIsInt($aDatePart[$x]) Then
  715. $aDatePart[$x] = Int($aDatePart[$x])
  716. Else
  717. $aDatePart[$x] = -1
  718. EndIf
  719. If StringIsInt($iTimePart[$x]) Then
  720. $iTimePart[$x] = Int($iTimePart[$x])
  721. Else
  722. $iTimePart[$x] = 0
  723. EndIf
  724. Next
  725. Return 1
  726. EndFunc ;==>_DateTimeSplit
  727. ; #FUNCTION# ====================================================================================================================
  728. ; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
  729. ; Modified.......:
  730. ; ===============================================================================================================================
  731. Func _DateToDayOfWeek($iYear, $iMonth, $iDay)
  732. ; Verify If InputDate is valid
  733. If Not _DateIsValid($iYear & "/" & $iMonth & "/" & $iDay) Then
  734. Return SetError(1, 0, "")
  735. EndIf
  736. Local $i_FactorA = Int((14 - $iMonth) / 12)
  737. Local $i_FactorY = $iYear - $i_FactorA
  738. Local $i_FactorM = $iMonth + (12 * $i_FactorA) - 2
  739. Local $i_FactorD = Mod($iDay + $i_FactorY + Int($i_FactorY / 4) - Int($i_FactorY / 100) + Int($i_FactorY / 400) + Int((31 * $i_FactorM) / 12), 7)
  740. Return $i_FactorD + 1
  741. EndFunc ;==>_DateToDayOfWeek
  742. ; #FUNCTION# ====================================================================================================================
  743. ; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
  744. ; Modified.......:
  745. ; ===============================================================================================================================
  746. Func _DateToDayOfWeekISO($iYear, $iMonth, $iDay)
  747. Local $iDow = _DateToDayOfWeek($iYear, $iMonth, $iDay)
  748. If @error Then
  749. Return SetError(1, 0, "")
  750. EndIf
  751. If $iDow >= 2 Then Return $iDow - 1
  752. Return 7
  753. EndFunc ;==>_DateToDayOfWeekISO
  754. ; #FUNCTION# ====================================================================================================================
  755. ; Author ........: Jos van der Zande / Jeremy Landes
  756. ; Modified.......:
  757. ; ===============================================================================================================================
  758. Func _DateToDayValue($iYear, $iMonth, $iDay)
  759. ; Verify If InputDate is valid
  760. If Not _DateIsValid(StringFormat("%04d/%02d/%02d", $iYear, $iMonth, $iDay)) Then
  761. Return SetError(1, 0, "")
  762. EndIf
  763. If $iMonth < 3 Then
  764. $iMonth = $iMonth + 12
  765. $iYear = $iYear - 1
  766. EndIf
  767. Local $i_FactorA = Int($iYear / 100)
  768. Local $i_FactorB = Int($i_FactorA / 4)
  769. Local $i_FactorC = 2 - $i_FactorA + $i_FactorB
  770. Local $i_FactorE = Int(1461 * ($iYear + 4716) / 4)
  771. Local $i_FactorF = Int(153 * ($iMonth + 1) / 5)
  772. Local $iJulianDate = $i_FactorC + $iDay + $i_FactorE + $i_FactorF - 1524.5
  773. Return $iJulianDate
  774. EndFunc ;==>_DateToDayValue
  775. ; #FUNCTION# ====================================================================================================================
  776. ; Author ........: Jason Brand <exodius at gmail dot com>
  777. ; Modified.......: guinness
  778. ; ===============================================================================================================================
  779. Func _DateToMonth($iMonNum, $iFormat = Default)
  780. If $iFormat = Default Then $iFormat = 0
  781. $iMonNum = Int($iMonNum)
  782. If Not __DateIsMonth($iMonNum) Then Return SetError(1, 0, "")
  783. Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
  784. DllStructSetData($tSYSTEMTIME, "Year", @YEAR)
  785. DllStructSetData($tSYSTEMTIME, "Month", $iMonNum)
  786. DllStructSetData($tSYSTEMTIME, "Day", 1)
  787. Return _WinAPI_GetDateFormat(BitAND($iFormat, $DMW_LOCALE_LONGNAME) ? $LOCALE_USER_DEFAULT : $LOCALE_INVARIANT, $tSYSTEMTIME, 0, BitAND($iFormat, $DMW_SHORTNAME) ? "MMM" : "MMMM")
  788. EndFunc ;==>_DateToMonth
  789. ; #FUNCTION# ====================================================================================================================
  790. ; Author ........: Jos van der Zande
  791. ; Modified.......:
  792. ; ===============================================================================================================================
  793. Func _DayValueToDate($iJulianDate, ByRef $iYear, ByRef $iMonth, ByRef $iDay)
  794. ; check for valid input date
  795. If $iJulianDate < 0 Or Not IsNumber($iJulianDate) Then
  796. Return SetError(1, 0, 0)
  797. EndIf
  798. ; calculte the date
  799. Local $i_FactorZ = Int($iJulianDate + 0.5)
  800. Local $i_FactorW = Int(($i_FactorZ - 1867216.25) / 36524.25)
  801. Local $i_FactorX = Int($i_FactorW / 4)
  802. Local $i_FactorA = $i_FactorZ + 1 + $i_FactorW - $i_FactorX
  803. Local $i_FactorB = $i_FactorA + 1524
  804. Local $i_FactorC = Int(($i_FactorB - 122.1) / 365.25)
  805. Local $i_FactorD = Int(365.25 * $i_FactorC)
  806. Local $i_FactorE = Int(($i_FactorB - $i_FactorD) / 30.6001)
  807. Local $i_FactorF = Int(30.6001 * $i_FactorE)
  808. $iDay = $i_FactorB - $i_FactorD - $i_FactorF
  809. ; (must get number less than or equal to 12)
  810. If $i_FactorE - 1 < 13 Then
  811. $iMonth = $i_FactorE - 1
  812. Else
  813. $iMonth = $i_FactorE - 13
  814. EndIf
  815. If $iMonth < 3 Then
  816. $iYear = $i_FactorC - 4715 ; (if Month is January or February)
  817. Else
  818. $iYear = $i_FactorC - 4716 ;(otherwise)
  819. EndIf
  820. $iYear = StringFormat("%04d", $iYear)
  821. $iMonth = StringFormat("%02d", $iMonth)
  822. $iDay = StringFormat("%02d", $iDay)
  823. Return $iYear & "/" & $iMonth & "/" & $iDay
  824. EndFunc ;==>_DayValueToDate
  825. ; #NO_DOC_FUNCTION# =============================================================================================================
  826. ; Name...........: _Date_JulianDayNo
  827. ; Description ...: Returns the the julian date in format YYDDD
  828. ; Syntax.........: _Date_JulianDayNo ( $iYear, $iMonth, $iDay )
  829. ; Parameters ....: $iJulianDate - Julian date number
  830. ; $iYear - Year in format YYYY
  831. ; $iMonth - Month in format MM
  832. ; $iDay - Day of the month format DD
  833. ; Return values .: Success - Returns the date calculated
  834. ; Failure - 0 and Set @error to:
  835. ; |0 - No error.
  836. ; |1 - Invalid Input number of days
  837. ; Author ........: Jeremy Landes / Jos van der Zande
  838. ; Modified.......:
  839. ; Remarks .......:
  840. ; Related .......:
  841. ; Link ..........:
  842. ; Example .......:
  843. ; ===============================================================================================================================
  844. Func _Date_JulianDayNo($iYear, $iMonth, $iDay)
  845. ; Verify If InputDate is valid
  846. Local $sFullDate = StringFormat("%04d/%02d/%02d", $iYear, $iMonth, $iDay)
  847. If Not _DateIsValid($sFullDate) Then
  848. Return SetError(1, 0, "")
  849. EndIf
  850. ; Build JDay value
  851. Local $iJDay = 0
  852. Local $aiDaysInMonth = _DaysInMonth($iYear)
  853. For $iCntr = 1 To $iMonth - 1
  854. $iJDay = $iJDay + $aiDaysInMonth[$iCntr]
  855. Next
  856. $iJDay = ($iYear * 1000) + ($iJDay + $iDay)
  857. Return $iJDay
  858. EndFunc ;==>_Date_JulianDayNo
  859. ; #NO_DOC_FUNCTION# =============================================================================================================
  860. ; Name...........: _JulianToDate
  861. ; Description ...: Returns the the julian date in format YYDDD
  862. ; Syntax.........: _JulianToDate ($iJDay [, $sSep = "/"] )
  863. ; Parameters ....: $iJDate - Julian date number
  864. ; $sSep - Seperator character
  865. ; Return values .: Success - Returns the Date in format YYYY/MM/DD
  866. ; Failure - 0 and Set @error to:
  867. ; |0 - No error.
  868. ; |1 - Invalid Julian
  869. ; Author ........: Jeremy Landes / Jos van der Zande
  870. ; Modified.......:
  871. ; Remarks .......:
  872. ; Related .......:
  873. ; Link ..........:
  874. ; Example .......:
  875. ; ===============================================================================================================================
  876. Func _JulianToDate($iJDay, $sSep = "/")
  877. ; Verify If InputDate is valid
  878. Local $iYear = Int($iJDay / 1000)
  879. Local $iDays = Mod($iJDay, 1000)
  880. Local $iMaxDays = 365
  881. If _DateIsLeapYear($iYear) Then $iMaxDays = 366
  882. If $iDays > $iMaxDays Then
  883. Return SetError(1, 0, "")
  884. EndIf
  885. ; Convert to regular date
  886. Local $aiDaysInMonth = _DaysInMonth($iYear)
  887. Local $iMonth = 1
  888. While $iDays > $aiDaysInMonth[$iMonth]
  889. $iDays = $iDays - $aiDaysInMonth[$iMonth]
  890. $iMonth = $iMonth + 1
  891. WEnd
  892. Return StringFormat("%04d%s%02d%s%02d", $iYear, $sSep, $iMonth, $sSep, $iDays)
  893. EndFunc ;==>_JulianToDate
  894. ; #FUNCTION# ====================================================================================================================
  895. ; Author ........: Jos van der Zande
  896. ; Modified.......:
  897. ; ===============================================================================================================================
  898. Func _Now()
  899. Return _DateTimeFormat(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC, 0)
  900. EndFunc ;==>_Now
  901. ; #FUNCTION# ====================================================================================================================
  902. ; Author ........: Jos van der Zande
  903. ; Modified.......:
  904. ; ===============================================================================================================================
  905. Func _NowCalc()
  906. Return @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC
  907. EndFunc ;==>_NowCalc
  908. ; #FUNCTION# ====================================================================================================================
  909. ; Author ........: Jos van der Zande
  910. ; Modified.......:
  911. ; ===============================================================================================================================
  912. Func _NowCalcDate()
  913. Return @YEAR & "/" & @MON & "/" & @MDAY
  914. EndFunc ;==>_NowCalcDate
  915. ; #FUNCTION# ====================================================================================================================
  916. ; Author ........: Jos van der Zande
  917. ; Modified.......:
  918. ; ===============================================================================================================================
  919. Func _NowDate()
  920. Return _DateTimeFormat(@YEAR & "/" & @MON & "/" & @MDAY, 0)
  921. EndFunc ;==>_NowDate
  922. ; #FUNCTION# ====================================================================================================================
  923. ; Author ........: Jos van der Zande
  924. ; Modified.......:
  925. ; ===============================================================================================================================
  926. Func _NowTime($sType = 3)
  927. If $sType < 3 Or $sType > 5 Then $sType = 3
  928. Return _DateTimeFormat(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC, $sType)
  929. EndFunc ;==>_NowTime
  930. ; #FUNCTION# ====================================================================================================================
  931. ; Author ........: /dev/null
  932. ; Modified.......:
  933. ; ===============================================================================================================================
  934. Func _SetDate($iDay, $iMonth = 0, $iYear = 0)
  935. ;============================================================================
  936. ;== Some error checking
  937. ;============================================================================
  938. If $iYear = 0 Then $iYear = @YEAR
  939. If $iMonth = 0 Then $iMonth = @MON
  940. If Not _DateIsValid($iYear & "/" & $iMonth & "/" & $iDay) Then Return 1
  941. Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
  942. ;============================================================================
  943. ;== Get the local system time to fill up the SYSTEMTIME structure
  944. ;============================================================================
  945. DllCall("kernel32.dll", "none", "GetLocalTime", "struct*", $tSYSTEMTIME)
  946. If @error Then Return SetError(@error, @extended, 0)
  947. ;============================================================================
  948. ;== Change the necessary values
  949. ;============================================================================
  950. DllStructSetData($tSYSTEMTIME, "Day", $iDay)
  951. If $iMonth > 0 Then DllStructSetData($tSYSTEMTIME, "Month", $iMonth)
  952. If $iYear > 0 Then DllStructSetData($tSYSTEMTIME, "Year", $iYear)
  953. ;============================================================================
  954. ;== Set the new date
  955. ;============================================================================
  956. Local $iReturn = _Date_Time_SetLocalTime($tSYSTEMTIME)
  957. If @error Then Return SetError(@error + 10, @extended, 0)
  958. Return Int($iReturn)
  959. EndFunc ;==>_SetDate
  960. ; #FUNCTION# ====================================================================================================================
  961. ; Author ........: /dev/null
  962. ; Modified.......:
  963. ; ===============================================================================================================================
  964. Func _SetTime($iHour, $iMinute, $iSecond = 0, $iMSeconds = 0)
  965. ;============================================================================
  966. ;== Some error checking
  967. ;============================================================================
  968. If $iHour < 0 Or $iHour > 23 Then Return 1
  969. If $iMinute < 0 Or $iMinute > 59 Then Return 1
  970. If $iSecond < 0 Or $iSecond > 59 Then Return 1
  971. If $iMSeconds < 0 Or $iMSeconds > 999 Then Return 1
  972. Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
  973. ;============================================================================
  974. ;== Get the local system time to fill up the SYSTEMTIME structure
  975. ;============================================================================
  976. DllCall("kernel32.dll", "none", "GetLocalTime", "struct*", $tSYSTEMTIME)
  977. If @error Then Return SetError(@error, @extended, 0)
  978. ;============================================================================
  979. ;== Change the necessary values
  980. ;============================================================================
  981. DllStructSetData($tSYSTEMTIME, "Hour", $iHour)
  982. DllStructSetData($tSYSTEMTIME, "Minute", $iMinute)
  983. If $iSecond > 0 Then DllStructSetData($tSYSTEMTIME, "Second", $iSecond)
  984. If $iMSeconds > 0 Then DllStructSetData($tSYSTEMTIME, "MSeconds", $iMSeconds)
  985. ;============================================================================
  986. ;== Set the new time
  987. ;============================================================================
  988. Local $iReturn = _Date_Time_SetLocalTime($tSYSTEMTIME)
  989. If @error Then Return SetError(@error + 10, @extended, 0)
  990. Return Int($iReturn)
  991. EndFunc ;==>_SetTime
  992. ; #FUNCTION# ====================================================================================================================
  993. ; Author ........: Marc <mrd at gmx de>
  994. ; Modified.......:
  995. ; ===============================================================================================================================
  996. Func _TicksToTime($iTicks, ByRef $iHours, ByRef $iMins, ByRef $iSecs)
  997. If Number($iTicks) > 0 Then
  998. $iTicks = Int($iTicks / 1000)
  999. $iHours = Int($iTicks / 3600)
  1000. $iTicks = Mod($iTicks, 3600)
  1001. $iMins = Int($iTicks / 60)
  1002. $iSecs = Mod($iTicks, 60)
  1003. ; If $iHours = 0 then $iHours = 24
  1004. Return 1
  1005. ElseIf Number($iTicks) = 0 Then
  1006. $iHours = 0
  1007. $iTicks = 0
  1008. $iMins = 0
  1009. $iSecs = 0
  1010. Return 1
  1011. Else
  1012. Return SetError(1, 0, 0)
  1013. EndIf
  1014. EndFunc ;==>_TicksToTime
  1015. ; #FUNCTION# ====================================================================================================================
  1016. ; Author ........: Marc <mrd at gmx de>
  1017. ; Modified.......: SlimShady: added the default time and made parameters optional
  1018. ; ===============================================================================================================================
  1019. Func _TimeToTicks($iHours = @HOUR, $iMins = @MIN, $iSecs = @SEC)
  1020. If StringIsInt($iHours) And StringIsInt($iMins) And StringIsInt($iSecs) Then
  1021. Local $iTicks = 1000 * ((3600 * $iHours) + (60 * $iMins) + $iSecs)
  1022. Return $iTicks
  1023. Else
  1024. Return SetError(1, 0, 0)
  1025. EndIf
  1026. EndFunc ;==>_TimeToTicks
  1027. ; #FUNCTION# ====================================================================================================================
  1028. ; Author ........: Tuape
  1029. ; Modified.......: JdeB: modified to UDF standards & Doc., Change calculation logic.
  1030. ; ===============================================================================================================================
  1031. Func _WeekNumberISO($iYear = @YEAR, $iMonth = @MON, $iDay = @MDAY)
  1032. ; Check for erroneous input in $Day, $Month & $Year
  1033. If $iDay > 31 Or $iDay < 1 Then
  1034. Return SetError(1, 0, -1)
  1035. ElseIf Not __DateIsMonth($iMonth) Then
  1036. Return SetError(2, 0, -1)
  1037. ElseIf $iYear < 1 Or $iYear > 2999 Then
  1038. Return SetError(3, 0, -1)
  1039. EndIf
  1040. Local $iDow = _DateToDayOfWeekISO($iYear, $iMonth, $iDay) - 1;
  1041. Local $iDow0101 = _DateToDayOfWeekISO($iYear, 1, 1) - 1;
  1042. If ($iMonth = 1 And 3 < $iDow0101 And $iDow0101 < 7 - ($iDay - 1)) Then
  1043. ;days before week 1 of the current year have the same week number as
  1044. ;the last day of the last week of the previous year
  1045. $iDow = $iDow0101 - 1;
  1046. $iDow0101 = _DateToDayOfWeekISO($iYear - 1, 1, 1) - 1;
  1047. $iMonth = 12
  1048. $iDay = 31
  1049. $iYear = $iYear - 1
  1050. ElseIf ($iMonth = 12 And 30 - ($iDay - 1) < _DateToDayOfWeekISO($iYear + 1, 1, 1) - 1 And _DateToDayOfWeekISO($iYear + 1, 1, 1) - 1 < 4) Then
  1051. ; days after the last week of the current year have the same week number as
  1052. ; the first day of the next year, (i.e. 1)
  1053. Return 1;
  1054. EndIf
  1055. Return Int((_DateToDayOfWeekISO($iYear, 1, 1) - 1 < 4) + 4 * ($iMonth - 1) + (2 * ($iMonth - 1) + ($iDay - 1) + $iDow0101 - $iDow + 6) * 36 / 256)
  1056. EndFunc ;==>_WeekNumberISO
  1057. ; #NO_DOC_FUNCTION# =============================================================================================================
  1058. ; Name...........: _WeekNumber
  1059. ; Description ...: Find out the week number of current date OR date given in parameters
  1060. ; Syntax.........: _WeekNumber ( [$iYear = @YEAR [, $iMonth = @MON [, $iDay = @MDAY [, $iWeekStart = 1]]]] )
  1061. ; Parameters ....: $iYear - Year value (default = current year)
  1062. ; $iMonth - Month value (default = current month)
  1063. ; $iDay - Day value (default = current day)
  1064. ; $iWeekStart - Week starts from Sunday (1, default) or Monday (2)
  1065. ; Return values .: Success - Returns week number of given date
  1066. ; Failure - -1 and sets @error to:
  1067. ; | 1 - On faulty parameters
  1068. ; |99 - On non-acceptable weekstart and uses default (Sunday) as starting day
  1069. ; Author ........: JdeB
  1070. ; Modified.......:
  1071. ; Remarks .......:
  1072. ; Related .......:
  1073. ; Link ..........:
  1074. ; Example .......:
  1075. ; ===============================================================================================================================
  1076. Func _WeekNumber($iYear = @YEAR, $iMonth = @MON, $iDay = @MDAY, $iWeekStart = 1)
  1077. ; Check for erroneous input in $Day, $Month & $Year
  1078. If $iDay > 31 Or $iDay < 1 Then
  1079. Return SetError(1, 0, -1)
  1080. ElseIf Not __DateIsMonth($iMonth) Then
  1081. Return SetError(3, 0, -1)
  1082. ElseIf $iYear < 1 Or $iYear > 2999 Then
  1083. Return SetError(4, 0, -1)
  1084. ElseIf $iWeekStart < 1 Or $iWeekStart > 2 Then
  1085. Return SetError(2, 0, -1)
  1086. EndIf
  1087. ;
  1088. Local $iStartWeek1, $iEndWeek1
  1089. ;$iDow = _DateToDayOfWeekISO($iYear, $iMonth, $iDay);
  1090. Local $iDow0101 = _DateToDayOfWeekISO($iYear, 1, 1);
  1091. Local $iDate = $iYear & '/' & $iMonth & '/' & $iDay
  1092. ;Calculate the Start and End date of Week 1 this year
  1093. If $iWeekStart = 1 Then
  1094. If $iDow0101 = 6 Then
  1095. $iStartWeek1 = 0
  1096. Else
  1097. $iStartWeek1 = -1 * $iDow0101 - 1
  1098. EndIf
  1099. $iEndWeek1 = $iStartWeek1 + 6
  1100. Else
  1101. $iStartWeek1 = $iDow0101 * -1
  1102. $iEndWeek1 = $iStartWeek1 + 6
  1103. EndIf
  1104. Local $iStartWeek1ny
  1105. ;$iStartWeek1Date = _DateAdd('d',$iStartWeek1,$iYear & '/01/01')
  1106. Local $iEndWeek1Date = _DateAdd('d', $iEndWeek1, $iYear & '/01/01')
  1107. ;Calculate the Start and End date of Week 1 this Next year
  1108. Local $iDow0101ny = _DateToDayOfWeekISO($iYear + 1, 1, 1);
  1109. ; 1 = start on Sunday / 2 = start on Monday
  1110. If $iWeekStart = 1 Then
  1111. If $iDow0101ny = 6 Then
  1112. $iStartWeek1ny = 0
  1113. Else
  1114. $iStartWeek1ny = -1 * $iDow0101ny - 1
  1115. EndIf
  1116. ;$IEndWeek1ny = $iStartWeek1ny + 6
  1117. Else
  1118. $iStartWeek1ny = $iDow0101ny * -1
  1119. ;$IEndWeek1ny = $iStartWeek1ny + 6
  1120. EndIf
  1121. Local $iStartWeek1Dateny = _DateAdd('d', $iStartWeek1ny, $iYear + 1 & '/01/01')
  1122. ;$iEndWeek1Dateny = _DateAdd('d',$IEndWeek1ny,$iYear+1 & '/01/01')
  1123. ;number of days after end week 1
  1124. Local $iCurrDateDiff = _DateDiff('d', $iEndWeek1Date, $iDate) - 1
  1125. ;number of days before next week 1 start
  1126. Local $iCurrDateDiffny = _DateDiff('d', $iStartWeek1Dateny, $iDate)
  1127. ;
  1128. ; Check for end of year
  1129. If $iCurrDateDiff >= 0 And $iCurrDateDiffny < 0 Then Return 2 + Int($iCurrDateDiff / 7)
  1130. ; > week 1
  1131. If $iCurrDateDiff < 0 Or $iCurrDateDiffny >= 0 Then Return 1
  1132. EndFunc ;==>_WeekNumber
  1133. ; #NO_DOC_FUNCTION# =============================================================================================================
  1134. ; Name...........: _DaysInMonth
  1135. ; Description ...: returns an Array that contains the numbers of days per month
  1136. ; Syntax.........: _DaysInMonth ( $iYear )
  1137. ; Parameters ....: $iYear - Year value
  1138. ; Return values .: Success - Array that contains the numbers of days per month
  1139. ; Failure - none
  1140. ; Author ........: Jos van der Zande / Jeremy Landes
  1141. ; Modified.......:
  1142. ; Remarks .......:
  1143. ; Related .......:
  1144. ; Link ..........:
  1145. ; Example .......:
  1146. ; ===============================================================================================================================
  1147. Func _DaysInMonth($iYear)
  1148. Local $aDays = [12, 31, (_DateIsLeapYear($iYear) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  1149. Return $aDays
  1150. EndFunc ;==>_DaysInMonth
  1151. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  1152. ; Name...........: __Date_Time_CloneSystemTime
  1153. ; Description ...: Clones a tagSYSTEMTIME structure
  1154. ; Syntax.........: __Date_Time_CloneSystemTime ( $pSystemTime )
  1155. ; Parameters ....: $pSystemTime - Pointer to a tagSYSTEMTIME structure
  1156. ; Return values .: Success - tagSYSTEMTIME structure containing the cloned system time
  1157. ; Author ........: Paul Campbell (PaulIA)
  1158. ; Modified.......:
  1159. ; Remarks .......: This function is used internally by Auto3Lib
  1160. ; Related .......: $tagSYSTEMTIME
  1161. ; Link ..........:
  1162. ; Example .......:
  1163. ; ===============================================================================================================================
  1164. Func __Date_Time_CloneSystemTime($pSystemTime)
  1165. Local $tSystemTime1 = DllStructCreate($tagSYSTEMTIME, $pSystemTime)
  1166. Local $tSystemTime2 = DllStructCreate($tagSYSTEMTIME)
  1167. DllStructSetData($tSystemTime2, "Month", DllStructGetData($tSystemTime1, "Month"))
  1168. DllStructSetData($tSystemTime2, "Day", DllStructGetData($tSystemTime1, "Day"))
  1169. DllStructSetData($tSystemTime2, "Year", DllStructGetData($tSystemTime1, "Year"))
  1170. DllStructSetData($tSystemTime2, "Hour", DllStructGetData($tSystemTime1, "Hour"))
  1171. DllStructSetData($tSystemTime2, "Minute", DllStructGetData($tSystemTime1, "Minute"))
  1172. DllStructSetData($tSystemTime2, "Second", DllStructGetData($tSystemTime1, "Second"))
  1173. DllStructSetData($tSystemTime2, "MSeconds", DllStructGetData($tSystemTime1, "MSeconds"))
  1174. DllStructSetData($tSystemTime2, "DOW", DllStructGetData($tSystemTime1, "DOW"))
  1175. Return $tSystemTime2
  1176. EndFunc ;==>__Date_Time_CloneSystemTime
  1177. ; #FUNCTION# ====================================================================================================================
  1178. ; Author ........: Paul Campbell (PaulIA)
  1179. ; Modified.......: jpm
  1180. ; ===============================================================================================================================
  1181. Func _Date_Time_CompareFileTime($tFileTime1, $tFileTime2)
  1182. Local $aResult = DllCall("kernel32.dll", "long", "CompareFileTime", "struct*", $tFileTime1, "struct*", $tFileTime2)
  1183. If @error Then Return SetError(@error, @extended, 0)
  1184. Return $aResult[0]
  1185. EndFunc ;==>_Date_Time_CompareFileTime
  1186. ; #FUNCTION# ====================================================================================================================
  1187. ; Author ........: Paul Campbell (PaulIA)
  1188. ; Modified.......:
  1189. ; ===============================================================================================================================
  1190. Func _Date_Time_DOSDateTimeToFileTime($iFatDate, $iFatTime)
  1191. Local $tTime = DllStructCreate($tagFILETIME)
  1192. Local $aResult = DllCall("kernel32.dll", "bool", "DosDateTimeToFileTime", "word", $iFatDate, "word", $iFatTime, "struct*", $tTime)
  1193. If @error Then Return SetError(@error, @extended, 0)
  1194. Return SetExtended($aResult[0], $tTime)
  1195. EndFunc ;==>_Date_Time_DOSDateTimeToFileTime
  1196. ; #FUNCTION# ====================================================================================================================
  1197. ; Author ........: Paul Campbell (PaulIA)
  1198. ; Modified.......:
  1199. ; ===============================================================================================================================
  1200. Func _Date_Time_DOSDateToArray($iDosDate)
  1201. Local $aDate[3]
  1202. $aDate[0] = BitAND($iDosDate, 0x1F)
  1203. $aDate[1] = BitAND(BitShift($iDosDate, 5), 0x0F)
  1204. $aDate[2] = BitAND(BitShift($iDosDate, 9), 0x3F) + 1980
  1205. Return $aDate
  1206. EndFunc ;==>_Date_Time_DOSDateToArray
  1207. ; #FUNCTION# ====================================================================================================================
  1208. ; Author ........: Paul Campbell (PaulIA)
  1209. ; Modified.......:
  1210. ; ===============================================================================================================================
  1211. Func _Date_Time_DOSDateTimeToArray($iDosDate, $iDosTime)
  1212. Local $aDate[6]
  1213. $aDate[0] = BitAND($iDosDate, 0x1F)
  1214. $aDate[1] = BitAND(BitShift($iDosDate, 5), 0x0F)
  1215. $aDate[2] = BitAND(BitShift($iDosDate, 9), 0x3F) + 1980
  1216. $aDate[5] = BitAND($iDosTime, 0x1F) * 2
  1217. $aDate[4] = BitAND(BitShift($iDosTime, 5), 0x3F)
  1218. $aDate[3] = BitAND(BitShift($iDosTime, 11), 0x1F)
  1219. Return $aDate
  1220. EndFunc ;==>_Date_Time_DOSDateTimeToArray
  1221. ; #FUNCTION# ====================================================================================================================
  1222. ; Author ........: Paul Campbell (PaulIA)
  1223. ; Modified.......:
  1224. ; ===============================================================================================================================
  1225. Func _Date_Time_DOSDateTimeToStr($iDosDate, $iDosTime)
  1226. Local $aDate = _Date_Time_DOSDateTimeToArray($iDosDate, $iDosTime)
  1227. Return StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aDate[0], $aDate[1], $aDate[2], $aDate[3], $aDate[4], $aDate[5])
  1228. EndFunc ;==>_Date_Time_DOSDateTimeToStr
  1229. ; #FUNCTION# ====================================================================================================================
  1230. ; Author ........: Paul Campbell (PaulIA)
  1231. ; Modified.......:
  1232. ; ===============================================================================================================================
  1233. Func _Date_Time_DOSDateToStr($iDosDate)
  1234. Local $aDate = _Date_Time_DOSDateToArray($iDosDate)
  1235. Return StringFormat("%02d/%02d/%04d", $aDate[0], $aDate[1], $aDate[2])
  1236. EndFunc ;==>_Date_Time_DOSDateToStr
  1237. ; #FUNCTION# ====================================================================================================================
  1238. ; Author ........: Paul Campbell (PaulIA)
  1239. ; Modified.......:
  1240. ; ===============================================================================================================================
  1241. Func _Date_Time_DOSTimeToArray($iDosTime)
  1242. Local $aTime[3]
  1243. $aTime[2] = BitAND($iDosTime, 0x1F) * 2
  1244. $aTime[1] = BitAND(BitShift($iDosTime, 5), 0x3F)
  1245. $aTime[0] = BitAND(BitShift($iDosTime, 11), 0x1F)
  1246. Return $aTime
  1247. EndFunc ;==>_Date_Time_DOSTimeToArray
  1248. ; #FUNCTION# ====================================================================================================================
  1249. ; Author ........: Paul Campbell (PaulIA)
  1250. ; Modified.......:
  1251. ; ===============================================================================================================================
  1252. Func _Date_Time_DOSTimeToStr($iDosTime)
  1253. Local $aTime = _Date_Time_DOSTimeToArray($iDosTime)
  1254. Return StringFormat("%02d:%02d:%02d", $aTime[0], $aTime[1], $aTime[2])
  1255. EndFunc ;==>_Date_Time_DOSTimeToStr
  1256. ; #FUNCTION# ====================================================================================================================
  1257. ; Author ........: Paul Campbell (PaulIA)
  1258. ; Modified.......:
  1259. ; ===============================================================================================================================
  1260. Func _Date_Time_EncodeFileTime($iMonth, $iDay, $iYear, $iHour = 0, $iMinute = 0, $iSecond = 0, $iMSeconds = 0)
  1261. Local $tSYSTEMTIME = _Date_Time_EncodeSystemTime($iMonth, $iDay, $iYear, $iHour, $iMinute, $iSecond, $iMSeconds)
  1262. Return _Date_Time_SystemTimeToFileTime($tSYSTEMTIME)
  1263. EndFunc ;==>_Date_Time_EncodeFileTime
  1264. ; #FUNCTION# ====================================================================================================================
  1265. ; Author ........: Paul Campbell (PaulIA)
  1266. ; Modified.......:
  1267. ; ===============================================================================================================================
  1268. Func _Date_Time_EncodeSystemTime($iMonth, $iDay, $iYear, $iHour = 0, $iMinute = 0, $iSecond = 0, $iMSeconds = 0)
  1269. Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME)
  1270. DllStructSetData($tSYSTEMTIME, "Month", $iMonth)
  1271. DllStructSetData($tSYSTEMTIME, "Day", $iDay)
  1272. DllStructSetData($tSYSTEMTIME, "Year", $iYear)
  1273. DllStructSetData($tSYSTEMTIME, "Hour", $iHour)
  1274. DllStructSetData($tSYSTEMTIME, "Minute", $iMinute)
  1275. DllStructSetData($tSYSTEMTIME, "Second", $iSecond)
  1276. DllStructSetData($tSYSTEMTIME, "MSeconds", $iMSeconds)
  1277. Return $tSYSTEMTIME
  1278. EndFunc ;==>_Date_Time_EncodeSystemTime
  1279. ; #FUNCTION# ====================================================================================================================
  1280. ; Author ........: Paul Campbell (PaulIA)
  1281. ; Modified.......:
  1282. ; ===============================================================================================================================
  1283. Func _Date_Time_FileTimeToArray(ByRef $tFileTime)
  1284. If ((DllStructGetData($tFileTime, 1) + DllStructGetData($tFileTime, 2)) = 0) Then Return SetError(10, 0, 0)
  1285. Local $tSYSTEMTIME = _Date_Time_FileTimeToSystemTime($tFileTime)
  1286. If @error Then Return SetError(@error, @extended, 0)
  1287. Return _Date_Time_SystemTimeToArray($tSYSTEMTIME)
  1288. EndFunc ;==>_Date_Time_FileTimeToArray
  1289. ; #FUNCTION# ====================================================================================================================
  1290. ; Author ........: Paul Campbell (PaulIA)
  1291. ; Modified.......:
  1292. ; ===============================================================================================================================
  1293. Func _Date_Time_FileTimeToStr(ByRef $tFileTime, $iFmt = 0)
  1294. Local $aDate = _Date_Time_FileTimeToArray($tFileTime)
  1295. If @error Then Return SetError(@error, @extended, "")
  1296. If $iFmt Then
  1297. Return StringFormat("%04d/%02d/%02d %02d:%02d:%02d", $aDate[2], $aDate[0], $aDate[1], $aDate[3], $aDate[4], $aDate[5])
  1298. Else
  1299. Return StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aDate[0], $aDate[1], $aDate[2], $aDate[3], $aDate[4], $aDate[5])
  1300. EndIf
  1301. EndFunc ;==>_Date_Time_FileTimeToStr
  1302. ; #FUNCTION# ====================================================================================================================
  1303. ; Author ........: Paul Campbell (PaulIA)
  1304. ; Modified.......: jpm
  1305. ; ===============================================================================================================================
  1306. Func _Date_Time_FileTimeToDOSDateTime($tFileTime)
  1307. Local $aDate[2]
  1308. Local $aResult = DllCall("kernel32.dll", "bool", "FileTimeToDosDateTime", "struct*", $tFileTime, "word*", 0, "word*", 0)
  1309. If @error Then Return SetError(@error, @extended, $aDate)
  1310. $aDate[0] = $aResult[2]
  1311. $aDate[1] = $aResult[3]
  1312. Return SetExtended($aResult[0], $aDate)
  1313. EndFunc ;==>_Date_Time_FileTimeToDOSDateTime
  1314. ; #FUNCTION# ====================================================================================================================
  1315. ; Author ........: Paul Campbell (PaulIA)
  1316. ; Modified.......:
  1317. ; ===============================================================================================================================
  1318. Func _Date_Time_FileTimeToLocalFileTime($tFileTime)
  1319. Local $tLocal = DllStructCreate($tagFILETIME)
  1320. Local $aResult = DllCall("kernel32.dll", "bool", "FileTimeToLocalFileTime", "struct*", $tFileTime, "struct*", $tLocal)
  1321. If @error Then Return SetError(@error, @extended, 0)
  1322. Return SetExtended($aResult[0], $tLocal)
  1323. EndFunc ;==>_Date_Time_FileTimeToLocalFileTime
  1324. ; #FUNCTION# ====================================================================================================================
  1325. ; Author ........: Paul Campbell (PaulIA)
  1326. ; Modified.......:
  1327. ; ===============================================================================================================================
  1328. Func _Date_Time_FileTimeToSystemTime($tFileTime)
  1329. Local $tSystTime = DllStructCreate($tagSYSTEMTIME)
  1330. Local $aResult = DllCall("kernel32.dll", "bool", "FileTimeToSystemTime", "struct*", $tFileTime, "struct*", $tSystTime)
  1331. If @error Then Return SetError(@error, @extended, 0)
  1332. Return SetExtended($aResult[0], $tSystTime)
  1333. EndFunc ;==>_Date_Time_FileTimeToSystemTime
  1334. ; #FUNCTION# ====================================================================================================================
  1335. ; Author ........: Paul Campbell (PaulIA)
  1336. ; Modified.......:
  1337. ; ===============================================================================================================================
  1338. Func _Date_Time_GetFileTime($hFile)
  1339. Local $aDate[3]
  1340. $aDate[0] = DllStructCreate($tagFILETIME)
  1341. $aDate[1] = DllStructCreate($tagFILETIME)
  1342. $aDate[2] = DllStructCreate($tagFILETIME)
  1343. Local $aResult = DllCall("kernel32.dll", "bool", "GetFileTime", "handle", $hFile, "struct*", $aDate[0], "struct*", $aDate[1], "struct*", $aDate[2])
  1344. If @error Then Return SetError(@error, @extended, 0)
  1345. Return SetExtended($aResult[0], $aDate)
  1346. EndFunc ;==>_Date_Time_GetFileTime
  1347. ; #FUNCTION# ====================================================================================================================
  1348. ; Author ........: Paul Campbell (PaulIA)
  1349. ; Modified.......:
  1350. ; ===============================================================================================================================
  1351. Func _Date_Time_GetLocalTime()
  1352. Local $tSystTime = DllStructCreate($tagSYSTEMTIME)
  1353. DllCall("kernel32.dll", "none", "GetLocalTime", "struct*", $tSystTime)
  1354. If @error Then Return SetError(@error, @extended, 0)
  1355. Return $tSystTime
  1356. EndFunc ;==>_Date_Time_GetLocalTime
  1357. ; #FUNCTION# ====================================================================================================================
  1358. ; Author ........: Paul Campbell (PaulIA)
  1359. ; Modified.......:
  1360. ; ===============================================================================================================================
  1361. Func _Date_Time_GetSystemTime()
  1362. Local $tSystTime = DllStructCreate($tagSYSTEMTIME)
  1363. DllCall("kernel32.dll", "none", "GetSystemTime", "struct*", $tSystTime)
  1364. If @error Then Return SetError(@error, @extended, 0)
  1365. Return $tSystTime
  1366. EndFunc ;==>_Date_Time_GetSystemTime
  1367. ; #FUNCTION# ====================================================================================================================
  1368. ; Author ........: Paul Campbell (PaulIA)
  1369. ; Modified.......:
  1370. ; ===============================================================================================================================
  1371. Func _Date_Time_GetSystemTimeAdjustment()
  1372. Local $aInfo[3]
  1373. Local $aResult = DllCall("kernel32.dll", "bool", "GetSystemTimeAdjustment", "dword*", 0, "dword*", 0, "bool*", 0)
  1374. If @error Then Return SetError(@error, @extended, 0)
  1375. $aInfo[0] = $aResult[1]
  1376. $aInfo[1] = $aResult[2]
  1377. $aInfo[2] = $aResult[3] <> 0
  1378. Return SetExtended($aResult[0], $aInfo)
  1379. EndFunc ;==>_Date_Time_GetSystemTimeAdjustment
  1380. ; #FUNCTION# ====================================================================================================================
  1381. ; Author ........: Paul Campbell (PaulIA)
  1382. ; Modified.......:
  1383. ; ===============================================================================================================================
  1384. Func _Date_Time_GetSystemTimeAsFileTime()
  1385. Local $tFileTime = DllStructCreate($tagFILETIME)
  1386. DllCall("kernel32.dll", "none", "GetSystemTimeAsFileTime", "struct*", $tFileTime)
  1387. If @error Then Return SetError(@error, @extended, 0)
  1388. Return $tFileTime
  1389. EndFunc ;==>_Date_Time_GetSystemTimeAsFileTime
  1390. ; #FUNCTION# ====================================================================================================================
  1391. ; Author ........: Paul Campbell (PaulIA)
  1392. ; Modified.......:
  1393. ; ===============================================================================================================================
  1394. Func _Date_Time_GetSystemTimes()
  1395. Local $aInfo[3]
  1396. $aInfo[0] = DllStructCreate($tagFILETIME)
  1397. $aInfo[1] = DllStructCreate($tagFILETIME)
  1398. $aInfo[2] = DllStructCreate($tagFILETIME)
  1399. Local $aResult = DllCall("kernel32.dll", "bool", "GetSystemTimes", "struct*", $aInfo[0], "struct*", $aInfo[1], "struct*", $aInfo[2])
  1400. If @error Then Return SetError(@error, @extended, 0)
  1401. Return SetExtended($aResult[0], $aInfo)
  1402. EndFunc ;==>_Date_Time_GetSystemTimes
  1403. ; #FUNCTION# ====================================================================================================================
  1404. ; Author ........: Paul Campbell (PaulIA)
  1405. ; Modified.......:
  1406. ; ===============================================================================================================================
  1407. Func _Date_Time_GetTickCount()
  1408. Local $aResult = DllCall("kernel32.dll", "dword", "GetTickCount")
  1409. If @error Then Return SetError(@error, @extended, 0)
  1410. Return $aResult[0]
  1411. EndFunc ;==>_Date_Time_GetTickCount
  1412. ; #FUNCTION# ====================================================================================================================
  1413. ; Author ........: Paul Campbell (PaulIA)
  1414. ; Modified.......: Gary Frost (gafrost)
  1415. ; ===============================================================================================================================
  1416. Func _Date_Time_GetTimeZoneInformation()
  1417. Local $tTimeZone = DllStructCreate($tagTIME_ZONE_INFORMATION)
  1418. Local $aResult = DllCall("kernel32.dll", "dword", "GetTimeZoneInformation", "struct*", $tTimeZone)
  1419. If @error Or $aResult[0] = -1 Then Return SetError(@error, @extended, 0)
  1420. Local $aInfo[8]
  1421. $aInfo[0] = $aResult[0]
  1422. $aInfo[1] = DllStructGetData($tTimeZone, "Bias")
  1423. $aInfo[2] = DllStructGetData($tTimeZone, "StdName")
  1424. $aInfo[3] = __Date_Time_CloneSystemTime(DllStructGetPtr($tTimeZone, "StdDate"))
  1425. $aInfo[4] = DllStructGetData($tTimeZone, "StdBias")
  1426. $aInfo[5] = DllStructGetData($tTimeZone, "DayName")
  1427. $aInfo[6] = __Date_Time_CloneSystemTime(DllStructGetPtr($tTimeZone, "DayDate"))
  1428. $aInfo[7] = DllStructGetData($tTimeZone, "DayBias")
  1429. Return $aInfo
  1430. EndFunc ;==>_Date_Time_GetTimeZoneInformation
  1431. ; #FUNCTION# ====================================================================================================================
  1432. ; Author ........: Paul Campbell (PaulIA)
  1433. ; Modified.......: jpm
  1434. ; ===============================================================================================================================
  1435. Func _Date_Time_LocalFileTimeToFileTime($tLocalTime)
  1436. Local $tFileTime = DllStructCreate($tagFILETIME)
  1437. Local $aResult = DllCall("kernel32.dll", "bool", "LocalFileTimeToFileTime", "struct*", $tLocalTime, "struct*", $tFileTime)
  1438. If @error Then Return SetError(@error, @extended, 0)
  1439. Return SetExtended($aResult[0], $tFileTime)
  1440. EndFunc ;==>_Date_Time_LocalFileTimeToFileTime
  1441. ; #FUNCTION# ====================================================================================================================
  1442. ; Author ........: Paul Campbell (PaulIA)
  1443. ; Modified.......: jpm
  1444. ; ===============================================================================================================================
  1445. Func _Date_Time_SetFileTime($hFile, $tCreateTime, $tLastAccess, $tLastWrite)
  1446. Local $aResult = DllCall("kernel32.dll", "bool", "SetFileTime", "handle", $hFile, "struct*", $tCreateTime, "struct*", $tLastAccess, "struct*", $tLastWrite)
  1447. If @error Then Return SetError(@error, @extended, False)
  1448. Return $aResult[0]
  1449. EndFunc ;==>_Date_Time_SetFileTime
  1450. ; #FUNCTION# ====================================================================================================================
  1451. ; Author ........: Paul Campbell (PaulIA)
  1452. ; Modified.......:
  1453. ; ===============================================================================================================================
  1454. Func _Date_Time_SetLocalTime($tSYSTEMTIME)
  1455. Local $aResult = DllCall("kernel32.dll", "bool", "SetLocalTime", "struct*", $tSYSTEMTIME)
  1456. If @error Or Not $aResult[0] Then Return SetError(@error + 10, @extended, False)
  1457. ; The system uses UTC internally. When you call SetLocalTime, the system uses the current time zone information to perform the
  1458. ; conversion, incuding the daylight saving time setting. The system uses the daylight saving time setting of the current time,
  1459. ; not the new time you are setting. This is a "feature" according to Microsoft. In order to get around this, we have to call
  1460. ; the function twice. The first call sets the internal time zone and the second call sets the actual time.
  1461. $aResult = DllCall("kernel32.dll", "bool", "SetLocalTime", "struct*", $tSYSTEMTIME)
  1462. If @error Then Return SetError(@error, @extended, False)
  1463. Return $aResult[0]
  1464. EndFunc ;==>_Date_Time_SetLocalTime
  1465. ; #FUNCTION# ====================================================================================================================
  1466. ; Author ........: Paul Campbell (PaulIA)
  1467. ; Modified.......: jpm
  1468. ; ===============================================================================================================================
  1469. Func _Date_Time_SetSystemTime($tSYSTEMTIME)
  1470. Local $aResult = DllCall("kernel32.dll", "bool", "SetSystemTime", "struct*", $tSYSTEMTIME)
  1471. If @error Then Return SetError(@error, @extended, False)
  1472. Return $aResult[0]
  1473. EndFunc ;==>_Date_Time_SetSystemTime
  1474. ; #FUNCTION# ====================================================================================================================
  1475. ; Author ........: Paul Campbell (PaulIA)
  1476. ; Modified.......: Gary Frost (gafrost)
  1477. ; ===============================================================================================================================
  1478. Func _Date_Time_SetSystemTimeAdjustment($iAdjustment, $bDisabled)
  1479. ; Enable system time privileged mode
  1480. Local $hToken = _Security__OpenThreadTokenEx(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
  1481. If @error Then Return SetError(@error + 10, @extended, False)
  1482. _Security__SetPrivilege($hToken, "SeSystemtimePrivilege", True)
  1483. Local $iError = @error
  1484. Local $iLastError = @extended
  1485. Local $bRet = False
  1486. If Not @error Then
  1487. ; Set system time
  1488. Local $aResult = DllCall("kernel32.dll", "bool", "SetSystemTimeAdjustment", "dword", $iAdjustment, "bool", $bDisabled)
  1489. If @error Then
  1490. $iError = @error
  1491. $iLastError = @extended
  1492. ElseIf $aResult[0] Then
  1493. $bRet = True
  1494. Else
  1495. $iError = 20
  1496. $iLastError = _WinAPI_GetLastError()
  1497. EndIf
  1498. ; Disable system time privileged mode
  1499. _Security__SetPrivilege($hToken, "SeSystemtimePrivilege", False)
  1500. If Not $iError And @error Then $iError = 22
  1501. EndIf
  1502. _WinAPI_CloseHandle($hToken)
  1503. Return SetError($iError, $iLastError, $bRet)
  1504. EndFunc ;==>_Date_Time_SetSystemTimeAdjustment
  1505. ; #FUNCTION# ====================================================================================================================
  1506. ; Author ........: Paul Campbell (PaulIA)
  1507. ; Modified.......: Gary Frost (gafrost)
  1508. ; ===============================================================================================================================
  1509. Func _Date_Time_SetTimeZoneInformation($iBias, $sStdName, $tStdDate, $iStdBias, $sDayName, $tDayDate, $iDayBias)
  1510. Local $tZoneInfo = DllStructCreate($tagTIME_ZONE_INFORMATION)
  1511. DllStructSetData($tZoneInfo, "Bias", $iBias)
  1512. DllStructSetData($tZoneInfo, "StdName", $sStdName)
  1513. _MemMoveMemory($tStdDate, DllStructGetPtr($tZoneInfo, "StdDate"), DllStructGetSize($tStdDate))
  1514. DllStructSetData($tZoneInfo, "StdBias", $iStdBias)
  1515. DllStructSetData($tZoneInfo, "DayName", $sDayName)
  1516. _MemMoveMemory($tDayDate, DllStructGetPtr($tZoneInfo, "DayDate"), DllStructGetSize($tDayDate))
  1517. DllStructSetData($tZoneInfo, "DayBias", $iDayBias)
  1518. ; Enable time zone privileged mode
  1519. Local $hToken = _Security__OpenThreadTokenEx(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
  1520. If @error Then Return SetError(@error + 10, @extended, False)
  1521. _Security__SetPrivilege($hToken, "SeTimeZonePrivilege", True)
  1522. Local $iError = @error
  1523. Local $iLastError = @extended
  1524. Local $bRet = False
  1525. If Not @error Then
  1526. ; Set time zone information
  1527. Local $aResult = DllCall("kernel32.dll", "bool", "SetTimeZoneInformation", "struct*", $tZoneInfo)
  1528. If @error Then
  1529. $iError = @error
  1530. $iLastError = @extended
  1531. ElseIf $aResult[0] Then
  1532. $iLastError = 0
  1533. $bRet = True
  1534. Else
  1535. $iError = 20
  1536. $iLastError = _WinAPI_GetLastError()
  1537. EndIf
  1538. ; Disable time zone privileged mode
  1539. _Security__SetPrivilege($hToken, "SeTimeZonePrivilege", False)
  1540. If Not $iError And @error Then $iError = 22
  1541. EndIf
  1542. _WinAPI_CloseHandle($hToken)
  1543. Return SetError($iError, $iLastError, $bRet)
  1544. EndFunc ;==>_Date_Time_SetTimeZoneInformation
  1545. ; #FUNCTION# ====================================================================================================================
  1546. ; Author ........: Paul Campbell (PaulIA)
  1547. ; Modified.......:
  1548. ; ===============================================================================================================================
  1549. Func _Date_Time_SystemTimeToArray(ByRef $tSYSTEMTIME)
  1550. Local $aInfo[8]
  1551. $aInfo[0] = DllStructGetData($tSYSTEMTIME, "Month")
  1552. $aInfo[1] = DllStructGetData($tSYSTEMTIME, "Day")
  1553. $aInfo[2] = DllStructGetData($tSYSTEMTIME, "Year")
  1554. $aInfo[3] = DllStructGetData($tSYSTEMTIME, "Hour")
  1555. $aInfo[4] = DllStructGetData($tSYSTEMTIME, "Minute")
  1556. $aInfo[5] = DllStructGetData($tSYSTEMTIME, "Second")
  1557. $aInfo[6] = DllStructGetData($tSYSTEMTIME, "MSeconds")
  1558. $aInfo[7] = DllStructGetData($tSYSTEMTIME, "DOW")
  1559. Return $aInfo
  1560. EndFunc ;==>_Date_Time_SystemTimeToArray
  1561. ; #FUNCTION# ====================================================================================================================
  1562. ; Author ........: Paul Campbell (PaulIA)
  1563. ; Modified.......:
  1564. ; ===============================================================================================================================
  1565. Func _Date_Time_SystemTimeToDateStr(ByRef $tSYSTEMTIME, $iFmt = 0)
  1566. Local $aInfo = _Date_Time_SystemTimeToArray($tSYSTEMTIME)
  1567. If @error Then Return SetError(@error, @extended, "")
  1568. If $iFmt Then
  1569. Return StringFormat("%04d/%02d/%02d", $aInfo[2], $aInfo[0], $aInfo[1])
  1570. Else
  1571. Return StringFormat("%02d/%02d/%04d", $aInfo[0], $aInfo[1], $aInfo[2])
  1572. EndIf
  1573. EndFunc ;==>_Date_Time_SystemTimeToDateStr
  1574. ; #FUNCTION# ====================================================================================================================
  1575. ; Author ........: Paul Campbell (PaulIA)
  1576. ; Modified.......:
  1577. ; ===============================================================================================================================
  1578. Func _Date_Time_SystemTimeToDateTimeStr(ByRef $tSYSTEMTIME, $iFmt = 0)
  1579. Local $aInfo = _Date_Time_SystemTimeToArray($tSYSTEMTIME)
  1580. If @error Then Return SetError(@error, @extended, "")
  1581. If $iFmt Then
  1582. Return StringFormat("%04d/%02d/%02d %02d:%02d:%02d", $aInfo[2], $aInfo[0], $aInfo[1], $aInfo[3], $aInfo[4], $aInfo[5])
  1583. Else
  1584. Return StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aInfo[0], $aInfo[1], $aInfo[2], $aInfo[3], $aInfo[4], $aInfo[5])
  1585. EndIf
  1586. EndFunc ;==>_Date_Time_SystemTimeToDateTimeStr
  1587. ; #FUNCTION# ====================================================================================================================
  1588. ; Author ........: Paul Campbell (PaulIA)
  1589. ; Modified.......:
  1590. ; ===============================================================================================================================
  1591. Func _Date_Time_SystemTimeToFileTime($tSYSTEMTIME)
  1592. Local $tFileTime = DllStructCreate($tagFILETIME)
  1593. Local $aResult = DllCall("kernel32.dll", "bool", "SystemTimeToFileTime", "struct*", $tSYSTEMTIME, "struct*", $tFileTime)
  1594. If @error Then Return SetError(@error, @extended, 0)
  1595. Return SetExtended($aResult[0], $tFileTime)
  1596. EndFunc ;==>_Date_Time_SystemTimeToFileTime
  1597. ; #FUNCTION# ====================================================================================================================
  1598. ; Author ........: Paul Campbell (PaulIA)
  1599. ; Modified.......:
  1600. ; ===============================================================================================================================
  1601. Func _Date_Time_SystemTimeToTimeStr(ByRef $tSYSTEMTIME)
  1602. Local $aInfo = _Date_Time_SystemTimeToArray($tSYSTEMTIME)
  1603. Return StringFormat("%02d:%02d:%02d", $aInfo[3], $aInfo[4], $aInfo[5])
  1604. EndFunc ;==>_Date_Time_SystemTimeToTimeStr
  1605. ; #FUNCTION# ====================================================================================================================
  1606. ; Author ........: Paul Campbell (PaulIA)
  1607. ; Modified.......: jpm
  1608. ; ===============================================================================================================================
  1609. Func _Date_Time_SystemTimeToTzSpecificLocalTime($tUTC, $tTimeZone = 0)
  1610. Local $tLocalTime = DllStructCreate($tagSYSTEMTIME)
  1611. Local $aResult = DllCall("kernel32.dll", "bool", "SystemTimeToTzSpecificLocalTime", "struct*", $tTimeZone, "struct*", $tUTC, "struct*", $tLocalTime)
  1612. If @error Then Return SetError(@error, @extended, 0)
  1613. Return SetExtended($aResult[0], $tLocalTime)
  1614. EndFunc ;==>_Date_Time_SystemTimeToTzSpecificLocalTime
  1615. ; #FUNCTION# ====================================================================================================================
  1616. ; Author ........: Paul Campbell (PaulIA)
  1617. ; Modified.......: jpm
  1618. ; ===============================================================================================================================
  1619. Func _Date_Time_TzSpecificLocalTimeToSystemTime($tLocalTime, $tTimeZone = 0)
  1620. Local $tUTC = DllStructCreate($tagSYSTEMTIME)
  1621. Local $aResult = DllCall("kernel32.dll", "bool", "TzSpecificLocalTimeToSystemTime", "struct*", $tTimeZone, "struct*", $tLocalTime, "struct*", $tUTC)
  1622. If @error Then Return SetError(@error, @extended, 0)
  1623. Return SetExtended($aResult[0], $tUTC)
  1624. EndFunc ;==>_Date_Time_TzSpecificLocalTimeToSystemTime