Jump to content
c.haslam

A new approach to Date functions?

Recommended Posts

c.haslam

I have recently suggested, in Trac, some additions to the Help for _DateDiff(). My objective was to explain further what this function actually does (which to me is not what it should actually do). M23 replied by pointing out that there may be similar problems with _DateAdd().

As I see it, changing the code of these _Date functions is going to break user code. So the solution I see is to add equivalent functions to the UDF > Date group named _Date_Time_*, and to deprecate the existing _Date (and _Now) functions.

To ensure that the new functions work in a completely consistent manner, I suggest that:

  • Specifications for the new functions (including their names) be thoroughly hashed out in this forum until at least the Developers are convinced that these functions are completely consistent
  • While AutoIt is type-less, that there be a standard internal date format, e.g. 'yyyymmddhhmmssmmm' (where each character is a digit -- to a millisecond)
  • The internal format be such that as ancient a date as possible be representable
  • datetime parameters of _DateTime functions accept as many formats of dates and times as is reasonable
  • datetime parameters of _DateTime functions accept just a time
  • There be a _DateTime_InitOutputFormat() function that sets the format of a datetime returned from subsequent calls to all other _DateTime functions that return datetimes.
  • In examples, datetime variables be named to indicate their content: $dt_ date and time, $d_ date only, $t_ time only

Thoughts?


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
Melba23

c.haslam,

Just for interest, I am already working on some amended functions.  But I find some of your suggestions a little strange:

- Always happy for an open discussion.
- We already have a standard DTG: YYYY/MM/DD[ HH:MM:SS] - I fail to see why we should go down the @MSEC route, especially as AutoIt itself is so slow.
- The current DTG seems quite adequate for that.
- No, if we have a standard DTG then people need to use it - we expect people to use standard syntax elsewhere so why not here. (and I have a UDF to help convert)
- Perhaps - but I can see a few problems here.
- No, the standard DTG should be returned (my UDF might be useful here too).
- Too early to worry about that yet.

M23

 


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
c.haslam

Good to hear that you are working on the problems.


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
jchd

I believe that what you're after is support for juliandate, but the _Date functions don't work this way.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Jos

Pretty sure I have also written a Julian date UDF way back when I created the Date.au3 include library.
Doesn't look like it is in the Helpfile.

; #NO_DOC_FUNCTION# =============================================================================================================
; Name...........: _JulianToDate_JulianToDate
; Description ...: Returns the the julian date in format YYDDD
; Syntax.........: _JulianToDate ($iJDay [, $sSep = "/"] )
; Parameters ....: $iJDate  - Julian date number
;                  $sSep    - Seperator character
; Return values .: Success - Returns the Date in format YYYY/MM/DD
;                  Failure - 0 and Set @error to:
;                  |0 - No error.
;                  |1 - Invalid Julian
; Author ........: Jeremy Landes / Jos van der Zande
; #NO_DOC_FUNCTION# =============================================================================================================
; Name...........: _Date_JulianDayNo
; Description ...: Returns the the julian date in format YYDDD
; Syntax.........: _Date_JulianDayNo ( $iYear, $iMonth, $iDay )
; Parameters ....: $iJulianDate - Julian date number
;                  $iYear       - Year in format YYYY
;                  $iMonth      - Month in format MM
;                  $iDay        - Day of the month format DD
; Return values .: Success - Returns the date calculated
;                  Failure - 0 and Set @error to:
;                  |0 - No error.
;                  |1 - Invalid Input number of days
; Author ........: Jeremy Landes / Jos van der Zande

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jchd

I beg your pardon but this looks more like julian day functions. Juliandate is a real, which easily offers precision down to 100 nanosecond, if ever needed.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Jos

I beg your pardon but this looks more like julian day functions. Juliandate is a real, which easily offers precision down to 100 nanosecond, if ever needed.

:) No worries you did not hit a sore spot! Just saw the comment which triggered the old grey cells a bit.

Jos

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jchd

I respect grey cells, even under grey hair! BTW it's 10ns, 100ns was a typo.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
c.haslam

I suggest that the new DateTime functions work to a precision of a millisecond for several reasons:

  1. While AutoIt may be too slow on current PCs to reliably work to a millisecond, if Moore's Law (or something like it) holds, the day is coming when AutoIt will be able to handle milliseconds reliably. (Reliably is probably not the correct word, but may the reader understand.) With a precision of a millisecond, the DateTime functions will be ready for faster PCs.
  2. There are already functions that report time to a millisecond, e.g. TimerDiff(). To be consistent with what already exists in AutoIt, the new functions should be coded to work to a millisecond
  3. I have a script now that uses date-times to a millisecond ( or at least to tenths of a second)
  4. Until PCs get faster, the help for date-time functions should include something like Return values are guaranteed to be accurate to a second, and may be more accurate than this, depending on the speed of the processor - or some words like this.
  5. The user should be able to use date-time parameters to whatever precision he/she chooses, e.g. _Date_Time_Diff("2012","2015")

Julian dates may be a better approach than the one I suggest.

The script I mention above is an appointment calendar. It calls Run() to schedule tasks and reports. Several instances can be running simultaneously. It has a feature that prevents calls to schtasks being less than 200 msec apart. To meet this requirement, the date-time of last call to schtasks (to a msec) is logged to a file, and each instance delays its call to schtasks until 200 msec from the date-time a an instance last called schtasks.


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
BrewManNH

On a very fast computer running this very simple script, each iteration of the loop is taking about 40 +/- ms to run. Ms timing is probably possible, and if someone needs that type of precision, they can always create their own functions to do that. I don't see the need for it to be standard in AutoIt, as it benefits an extremely small minority of users that can do it themselves.

$string = ""
Global $Time, $Timer = TimerInit()
For $I = 1 To 100
    $Time = TimerDiff($Timer)
    $string &= "Elapsed time: " & $Time & @CRLF
Next
ConsoleWrite($string)

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
c.haslam

Strange! The last line written to the console by your script on my PC is Elapsed time: 0.37152356662624. Per the help file for TimerDiff()  (and running the example there) this is in milliseconds.

This PC is not particularly fast, but it does have an SSD.

What am I missing?

Edited by c.haslam

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
BrewManNH

Sorry, I had forgotten that I had changed the script before posting it. It originally ran longer.:oops:


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×