Extended Date [Windows, Linux, MacOS]

Share your advanced PureBasic knowledge/code with the community.
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: Extended Date [Windows, Linux, MacOS]

Post by Lord »

wilbert wrote:...

Code: Select all

...
It's Julian/Gregorian hybrid with a fixed cutover date of Oct 4/15, 1582.
It should be accurate up to a few million years.
It's fast, cross platform, no ASM and no API. :)
That is not a good idea. The transition from Julian to Gregorian is depending on the location.
In parts of northern europe the cutover date is Feb 19/28 1700.
In Greece in the year 1923, in China in 1949 ....
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Extended Date [Windows, Linux, MacOS]

Post by wilbert »

Lord wrote:That is not a good idea. The transition from Julian to Gregorian is depending on the location.
In parts of northern europe the cutover date is Feb 19/28 1700.
In Greece in the year 1923, in China in 1949 ....
Fortunately we all are entitled to our own opinions. :wink:
To me a transition depending on location seems like a bad idea.
If I store a date inside a program that something happened here on for example July 2nd, 1901 and someone in Greece gets presented a different date, things get very confusing. To me consistency is the most important thing.
I've seen the link Sicro quoted to the German forum with a function handling local cutover dates but if I'm not mistaken, such a table is only useful if you are programming the entire date system yourself.
If you combine it for example with the internal date system of Linux, you can skip a few days based on location but the leap days before that date are still wrong so the system still doesn't present the right local dates. :?
An alternative could be to use the ISO 8601 proleptic Gregorian calendar system which makes things a lot easier.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: Extended Date [Windows, Linux, MacOS]

Post by Lord »

wilbert wrote:
Lord wrote:...
Fortunately we all are entitled to our own opinions.
...
That's true.
I made my statement and leave you your opinion.
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Extended Date [Windows, Linux, MacOS]

Post by wilbert »

Lord wrote:That's true.
I made my statement and leave you your opinion.
Well, you did get me thinking and reading some more :wink:
From what I understand, PHP, MySQL, JavaScript, Python all use a proleptic Gregorian calendar.
It would make sense to use the same.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: Extended Date [Windows, Linux, MacOS]

Post by Lord »

wilbert wrote:...
From what I understand, PHP, MySQL, JavaScript, Python all use a proleptic Gregorian calendar.
It would make sense to use the same.
So, if all are doing the same error, it is wise to make the same?
Why not doing it better and avoid possible problems?

But, as I said, it's just my opinion.
Image
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 559
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Extended Date [Windows, Linux, MacOS]

Post by Sicro »

There are a few other projects that I want to finish first. Before I can deal with this issue again.
But I think now and then about how best to handle the time calculations.

https://www.youtube.com/watch?v=-5wpm-gesOY :lol:
It is very complex :(
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
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: Extended Date [Windows, Linux, MacOS]

Post by Lord »

Sicro wrote:There are a few other projects that I want to finish first. Before I can deal with this issue again.
But I think now and then about how best to handle the time calculations.

https://www.youtube.com/watch?v=-5wpm-gesOY :lol:
It is very complex :(
Who said live is easy? :wink:
Image
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Extended Date [Windows, Linux, MacOS]

Post by Olliv »

Ten years ago, I remembered a subject of a monthly book named "Sciences & Vie" (published near 1995).

The null point was Monday, January the 1st 1901.
And all consisted in adding and calculate the modulo 7. Dobro (renamed Zorro) told us the problem of a different february every 400 years, what it allowed me to make this :

Code: Select all

Global Dim Jour.S(6)
Jour(0) = "Lundi"
Jour(1) = "Mardi"
Jour(2) = "Mercredi"
Jour(3) = "Jeudi"
Jour(4) = "Vendredi"
Jour(5) = "Samedi"
Jour(6) = "Dimanche"

Procedure Equ(a, b)
 Protected s.L
 s = 0: If a = b: s = 1: EndIf
 ProcedureReturn s
EndProcedure

; Merci Dobro pour cet algo!
Procedure.L Bissex(x.L)
 Protected Result.L
 Result = (1 - Equ((x % 100), 0) )
 Result | Equ(((x >> 2) % 100), 0)
 Result & Equ((x % 4), 0)
 ProcedureReturn Result
EndProcedure

Procedure JoursDansUnMois(x.L, y.L)
 Protected Result.L
 Result = (30 + ((x & 1) ! (x / 8) ) )
 Result - (Equ(x, 2) * (2 - y) )
 ProcedureReturn Result
EndProcedure

Procedure.L JourJ(JJ.L, MM.L, AA.L)
 Protected JPM.L
 Protected J.L
 J = 0
 JPM = 0
 For i = 1900 To AA - 1: J + (365 + Bissex(i) ): Next
 For i = 1 To MM - 1: J + JoursDansUnMois(i, Bissex(AA) ):
Next
 J = ((J + JJ) - 1) % 7
 ProcedureReturn J
EndProcedure
Date$ = InputRequester("Saisie d'une date", "JJ/MM/AAAA",
"01/01/ 1900")
Debug Jour(JourJ(Val(StringField(Date$, 1, "/") ), Val
(StringField(Date$, 2, "/") ), Val(StringField(Date$, 3,
"/") ) ) ) + " " + Date$
(source)And Fred created BOOL() function which can replace Equ() procedure and simplify this also.
Post Reply