[All OS] Module DateTime - Date as Double Since 1970

Share your advanced PureBasic knowledge/code with the community.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by Sicro »

Bitblazer wrote:Like many other old time users here, i did often run into sources and example / tool links to private websites, source repositories, ftp hosts etc. which disappeared throughout the years. Actually posting a source on the purebasic forum, was by far the most reliable and stable archive method.
I myself have also repeatedly experienced that after a while links have led to no longer existing destinations (in the German PB forum I am a member since 2005). Therefore, I can agree with this. However, I have also had the experience of members leaving the forum because of a dispute and deleting all forum posts beforehand.
Bitblazer wrote:Here have a look at the PureBasic forum from 20 years ago thanks to the Wayback machine.
Apart from the fact that the Wayback Machine, while more reliable, is also an external service that could be shut down at some point.

When searching for an older source code, in most cases a specific version number is searched for instead of a date when it was archived. Therefore, the wayback engine is not useful for searching specific source code versions.
Bitblazer wrote:The real downside i see, is that it would create too much resource use (cost) for the forum if we started to post all "important" sources to a subsection of the forum ;)

But maybe essential snippets of max 75 lines would be acceptable.
Many already posted source codes go far beyond 75 lines, but this is not a big resource consumption. It would look different if many forum members start posting also the binary files belonging to the source codes (images, music etc.) encoded as Base64 in the forum.
Bitblazer wrote:Oh and about the "keeping old nonbuggy versions" point. At the time you use a modules, you compile it with a copy of the modules on your storage anyway. Simply create backups of any working project. Archive it whenever a project has a working or significant status (like a release version always should be archived for years for commercial projects).
It's not that simple. Let's assume the following scenario: The module source code has been published, is downloaded by another programmer for the first time, and the module has another module in a specified version as a dependency. So there is no local copy of all module-required source codes on the programmer's side.
Saki wrote:Furthermore, probably no one will notice or determine this.
With a niche software it will not be public anyway and it is not immediately visible whether the software was created with PB or whatever.

So there is always a difference, you are not allowed to do everything, but people tend to do what they are not allowed to do or should not do.
This does not justify going the wrong way again and again and publishing source codes without OpenSource licenses. The source code copyright holder shoot themselves in the own leg with it, because many programmers avoid source codes without OpenSource license for own (OpenSource) projects.

Small snippets of source code may not have the required threshold of originality for copyright to exist, but when the threshold is reached is not firmly defined and can only be answered by a lawyer.

Everyone can do it the way he wants, it's just well-intentioned advice from my side.
mk-soft wrote:The Linux version is not quite perfect with the "Locale" option.
Maybe this will help you:

Code: Select all

Structure tm Align #PB_Structure_AlignC
  tm_sec.l    ; 0 to 59 or up to 60 at leap second
  tm_min.l    ; 0 to 59
  tm_hour.l   ; 0 to 23
  tm_mday.l   ; Day of the month: 1 to 31
  tm_mon.l    ; Month: 0 to 11 (0 = January)
  tm_year.l   ; Number of years since the year 1900
  tm_wday.l   ; Weekday: 0 to 6, 0 = Sunday
  tm_yday.l   ; Days since the beginning of the year: 0 to 365 (365 is therefore 366 because after 1. January is counted)
  tm_isdst.l  ; Is summer time? tm_isdst > 0 = Yes
              ;                             tm_isdst = 0 = No
              ;                             tm_isdst < 0 = Unknown
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    tm_gmtoff.l ; Offset of UTC in seconds
    *tm_zone    ; Abbreviation of the time zone
  CompilerElse
    tm_zone.l   ; Placeholder
    tm_gmtoff.l ; Offset of UTC in seconds
    *tm_zone64  ; Abbreviation of the time zone
  CompilerEndIf
  
EndStructure

#SecondsInOneHour = 60 * 60

Define tm.tm
Define utc, local, diff
Define diff$

utc = time_(0)
If localtime_r_(@utc, @tm) <> 0
  local = timegm_(@tm)
EndIf
diff = (local - utc) / #SecondsInOneHour

If diff > -1
  diff$ = "UTC +" + Str(diff)
Else
  diff$ = "UTC -" + Str(diff)
EndIf

Debug "UTC:   " + Str(utc)
Debug "LOCAL: " + Str(local)
Debug "DIFF:  " + diff$
(code is free, no copyright exists :mrgreen: )

Sorry for triggering the discussion. Maybe a forum moderator can move it to a separate forum thread if it gets too much.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by Bitblazer »

Sicro wrote:
Bitblazer wrote:Here have a look at the PureBasic forum from 20 years ago thanks to the Wayback machine.
Apart from the fact that the Wayback Machine, while more reliable, is also an external service that could be shut down at some point.

When searching for an older source code, in most cases a specific version number is searched for instead of a date when it was archived. Therefore, the wayback engine is not useful for searching specific source code versions.
You can select any snapshot time from a graph and in that case, you select another point. Or you use a keyword search limited to the specific purebasic site on the wayback archive to find those other dependancies.

It could happen that a module is posted and erased between snapshots while some later module references the deleted module, but that sounds a bit unlikely and never happened to me yet.
If any module would be THAT unstable (no longterm support in some way), i would stay far away from using it.

The wayback archive might actually disappear some day, though i dont know if that is realistic, but there are other less known similar services.
Sicro wrote:
Bitblazer wrote:Oh and about the "keeping old nonbuggy versions" point. At the time you use a modules, you compile it with a copy of the modules on your storage anyway. Simply create backups of any working project. Archive it whenever a project has a working or significant status (like a release version always should be archived for years for commercial projects).
Sicro wrote:It's not that simple. Let's assume the following scenario: The module source code has been published, is downloaded by another programmer for the first time, and the module has another module in a specified version as a dependency. So there is no local copy of all module-required source codes on the programmer's side.
My previous answers cover this already - use the wayback machine and avoid integrating modules which arent stable and not longterm supported.
webpage - discord chat links -> purebasic GPT4All
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by BarryG »

I note with interest from the Wayback that an early Amiga version of PureBasic had a C/C++ to PureBasic converter tool. Wow, eh? Wonder how good it was.
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by Bitblazer »

BarryG wrote:I note with interest from the Wayback that an early Amiga version of PureBasic had a C/C++ to PureBasic converter tool. Wow, eh? Wonder how good it was.
Yes, it's quite an amusing and interesting trip into the past :D
webpage - discord chat links -> purebasic GPT4All
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by mk-soft »

Update v1.03.0
- Change Linux to API (Date limits on x86 ca. 1902 to 2038)

Even though the Linux version x86 does not support the full date range, I decided to use Linux API.
Fewer and fewer Linux x86 systems are supported.

About the project backup and code from the forum:
Everyone should do their own stack backup. As long as the source code is available, there should be no problem.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by Sicro »

Bitblazer wrote:You can select any snapshot time from a graph and in that case, you select another point. Or you use a keyword search limited to the specific purebasic site on the wayback archive to find those other dependancies.
The wayback machine is very useful, but in this case rather not. Sorry, but this is cumbersome and rather to be seen as a emergency solution. If a package manager had to go this way, it would be a nightmare.

If it works for you, then all is well.
Bitblazer wrote:If any module would be THAT unstable (no longterm support in some way), i would stay far away from using it.
[...]
My previous answers cover this already - use the wayback machine and avoid integrating modules which arent stable and not longterm supported.
If a module A is still being developed further, it is usually inevitable that API changes will be made at some point and the version will then no longer be compatible with older versions. This change can happen just when the developers of another module B that has module A as a dependency do not have time to make the adjustment fast enough. Now, if someone with a package manager downloads module B and automatically the dependency module A in the current version, module B will not work anymore, because it is not compatible with the new API changes of module A.

Therefore, in the package information that the package manager reads, specific versions of dependencies are defined (mostly version changes that do not affect the major version are allowed, because they do not break compatibility with older versions).

However, if only the latest version of module A is always present in the forum, module B will stop working until module B is adjusted according to the API changes in module A. From this point of view, all source codes posted in the forum are considered unstable (no long-term support), because there is always only one version (the newest).

The workaround with the wayback machine, as written, I do not see as a clean solution to this problem.

As a solution, new forum thread for each new major version of the module could be created. This way the relevant previous versions of the module are always available and older major versions can still be maintained with updates that would be backward compatible with the corresponding major version.

Then only the two disadvantages remains:
  • that source codes have to be copied from forum posts and pasted into locally created files, which is cumbersome and not a clean way (error-prone). With several source code files it becomes more and more cumbersome. In addition, the files must be named correctly, because otherwise the include file path in the source codes is not correct.
  • that only the thread creator can update the source code in the first thread post. Most forum members will probably only look at this one instead of looking in the other thread pages for other versions of the source code.
In addition, the forum should rather be used for discussions (with small source codes) only. This would also save a lot of scrolling if no huge source codes are inserted between the discussion.
mk-soft wrote:Even though the Linux version x86 does not support the full date range, I decided to use Linux API.
Linux 5.6 Is The First Kernel For 32-Bit Systems Ready To Run Past Year 2038
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by mk-soft »

Update v2.01.0
- Added: GetDateYear, GetDateMonth, etc

Uses OS specific API and no ASM. Therefore also runs with C-Backend and Raspberry :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by mk-soft »

Update v2.02.1
- Added: GetDateFromValue(Year, ...)
- Change: GetDateNow remove parameter local. Date value must be alway as UTC
- Change: GetStringFromDate parameter order. Local as last parameter.
- Change: GetDateFromString parameter order. Local as last parameter.
- Bugfix: Get/SetCalendarDate to valid local date.
- Fix: Calculation of date double at windows. Rounding error from windows to the result from macOS or Linux result.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by mk-soft »

Update v2.02.2
- Update Set/GetCalendarDate
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by mk-soft »

Update v2.02.4
- Bugfix Linux SetCalendarDate
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by mk-soft »

Update v2.03.1
- Added: FormatString with Milliseconds ("%hh:%ii:%ss.%nnn")
- Fix Linux: GetDateNow() with Milliseconds
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by Cyllceaux »

I see, the year 100 is the lowest year on windows.

Code: Select all

    tdq.d=GetDateFromString("0100-01-01","%yyyy-%mm-%dd")
    Debug "MM: "+ tdq
    Debug "NN: "+ GetStringFromDate(tdq)
Everything lower does not work. :(
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [All OS] Module DateTime - Date as Double Since 1970

Post by mk-soft »

Hmm,

Only on windows ...

Link OLE-Automation: https://learn.microsoft.com/en-us/windo ... arianttime

Limit MacOS : "0001-01-01"
Limit Linux: "0000-01-01"
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply