DateEx: Extended Date library
Re: DateEx: Extended Date library
Wow, this is great! Thanks Little John!!!
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
- Mindphazer
- Enthusiast
- Posts: 456
- Joined: Mon Sep 10, 2012 10:41 am
- Location: Savoie
Re: DateEx: Extended Date library
Hello Little John
Sorry if i'm being noob, but where can i find the PureUnit.res file, needed to make the Assert() macro work ?
Thanks
Sorry if i'm being noob, but where can i find the PureUnit.res file, needed to make the Assert() macro work ?
Thanks
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
...and unfortunately... Windows at work...
-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library
Thanks for your kind words.

I did a lot testing, and I think the module is pretty stable and versatile now.
No problem. By default, the "PureUnit.res" file is located in the "Sdk\PureUnit\" subdirectory of the directory where PureBasic is installed.Mindphazer wrote: Tue Aug 01, 2023 5:23 pm Sorry if i'm being noob, but where can i find the PureUnit.res file, needed to make the Assert() macro work ?
Unfortunately, that doesn't make sense.

- Mindphazer
- Enthusiast
- Posts: 456
- Joined: Mon Sep 10, 2012 10:41 am
- Location: Savoie
Re: DateEx: Extended Date library
Oh thanks, I wasn't aware of thatLittle John wrote: Tue Aug 01, 2023 7:05 pm No problem. By default, the "PureUnit.res" file is located in the "Sdk\PureUnit\" subdirectory of the directory where PureBasic is installed.
Unfortunately, that doesn't make sense.![]()
Just tried your code "as is", but it stops at line 1217 (CallDebugger)
Code: Select all
Assert(DateQ() = Date())
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
...and unfortunately... Windows at work...
-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library
For getting the current time, DateQ() has to call an API function of the respective operating system.Mindphazer wrote: Tue Aug 01, 2023 7:56 pm Just tried your code "as is", but it stops at line 1217 (CallDebugger)But as I'm on a MacBook M1, that may be the reason...Code: Select all
Assert(DateQ() = Date())
Unfortunately, I don't know anything about Mac OS, and I don't have a possibility to test code on a Mac computer.
I didn't mention that explicitely. However, at the very top of the code, it reads:
Code: Select all
; successfully tested with
; [v] PB 6.02 LTS (x86) on Windows 11 – only ASM backend
; [v] PB 6.02 LTS (x64) on Windows 11 – both ASM and C backend (code not optimized!)
; [v] PB 6.03 beta 3 (x64) on Linux Mint 20.3 – both ASM and C backend (code not optimized!)
In the code, there are the following lines:
Code: Select all
405 CompilerCase #PB_OS_MacOS
406 g_Error = #Err_OSnotSupported
407 ProcedureReturn -1
- Mindphazer
- Enthusiast
- Posts: 456
- Joined: Mon Sep 10, 2012 10:41 am
- Location: Savoie
Re: DateEx: Extended Date library
Not your fault.Little John wrote: Tue Aug 01, 2023 8:27 pm For getting the current time, DateQ() has to call an API function of the respective operating system.
Unfortunately, I don't know anything about Mac OS, and I don't have a possibility to test code on a Mac computer.
I didn't mention that explicitely. However, at the very top of the code, it reads:I believed that not mentioning Mac there was clear enough. Obviously I was wrong.Code: Select all
; successfully tested with ; [v] PB 6.02 LTS (x86) on Windows 11 – only ASM backend ; [v] PB 6.02 LTS (x64) on Windows 11 – both ASM and C backend (code not optimized!) ; [v] PB 6.03 beta 3 (x64) on Linux Mint 20.3 – both ASM and C backend (code not optimized!)
Mine. I did read the top of your code. I just.... tried

Don't be sorry, it's okay. I'll try your code tomorrow on WindowsLittle John wrote: Tue Aug 01, 2023 8:27 pm In the code, there are the following lines:That's why you got an error. I am sorry for any inconveniences.Code: Select all
405 CompilerCase #PB_OS_MacOS 406 g_Error = #Err_OSnotSupported 407 ProcedureReturn -1
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
...and unfortunately... Windows at work...
-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library
New version 1.21, 2023-08-10
Fixed
Fixed
- DayOfWeekQ() returned a wrong result for 0001-01-01.
- Better error message on operating systems other than Windows or Linux.
- On success, the return value of DateDiff() is not always 1 anymore, but the difference endTime - startTime. This makes usage of the function sometimes more convenient.
- Slightly improved comments.
- Public macro Today(), that returns the date value for the current day at time 00:00:00. This comes in handy when calculating with whole days, regardless of the time of day.
- Mindphazer
- Enthusiast
- Posts: 456
- Joined: Mon Sep 10, 2012 10:41 am
- Location: Savoie
Re: DateEx: Extended Date library
That's for me, right ?Little John wrote: Thu Aug 10, 2023 2:30 pm [*]Better error message on operating systems other than Windows or Linux.

MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
...and unfortunately... Windows at work...
-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library

You really pointed out a weakness. Thanks for that!
-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library
As I wrote before, I wasn't able to reproduce that bug on Windows 11, but today I stumbled across it on Linux Mint (x64).jassing wrote: Wed Jul 05, 2023 6:15 pm I tried with pb6.00, asm - line 412 _splitdateq() "Procedure stack has been corrupted"

New version 1.22, 2023-09-10
Fixed
- One parameter of one procedure was a pointer to a not fitting structure,
under some circumstances resulting in the error “Procedure stack has been corrupted.”
Re: DateEx: Extended Date library
I was actually going to write something that makes Date() and Weekday() much nicer, but you beat me to it! Thanks a ton! 

-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library
Hi Quin,
I'm glad that the code is useful for you.
I'm glad that the code is useful for you.

-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library
Demo program
Code: Select all
; tested with PB 5.73 LTS, 6.04 LTS
; Create an annual overview calendar
EnableExplicit
XIncludeFile "DateEx.pbi"
UseModule DateEx
Procedure.i CalcOneMonth (year.i, month.i, Array monthCal.i(2))
; in : year, month
; out: monthCal()
; return value: column index of last week in this month
Protected.i firstMo, lastMo, lastWeek, week, day, lastDay, weekDay
; -- Preparation
firstMo = DayQ(nth_WeekDay_InMonth(#Monday, 1, year, month))
lastMo = DayQ(nth_WeekDay_InMonth(#monday, -1, year, month))
lastWeek = Int((lastMo - firstMo) / 7)
If firstMo > 1
lastWeek + 1
day = firstMo
Else
day = firstMo + 7
EndIf
Dim monthCal(7, lastWeek)
; -- Week numbers
monthCal(0, 0) = WeekNumber(DateQ(year, month, 1))
For week = 1 To lastWeek
monthCal(0, week) = WeekNumber(DateQ(year, month, day))
day + 7
Next
; -- Days
lastDay = DaysInMonth(year, month)
week = 0
For day = 1 To lastDay
weekDay = DayOfWeekQ(DateQ(year, month, day), #True)
monthCal(weekDay, week) = day
If weekDay = #SundayISO
week + 1
EndIf
Next
ProcedureReturn lastWeek
EndProcedure
Procedure Calendar (year.i)
Protected Dim monthCal.i(7, 0)
Protected.i month, lastWeek, week, weekDay, day
Protected line$
Debug "# " + year
Debug ""
For month = 1 To 12
lastWeek = CalcOneMonth(year, month, monthCal())
; -- Markdown output
Debug "## " + LocalizedMonthName(month)
Debug ""
line$ = "|w |" ; week number
For week = 0 To lastWeek
line$ + RSet(Str(monthCal(0, week)), 2) + "|"
Next
Debug line$
line$ = "|--|"
For week = 0 To lastWeek
line$ + "--|"
Next
Debug line$
For weekDay = 1 To 7
line$ = "|" + LocalizedDayName(weekDay, #True) + "|"
For week = 0 To lastWeek
day = monthCal(weekDay, week)
If day = 0
line$ + " |"
Else
line$ + RSet(Str(day), 2) + "|"
EndIf
Next
Debug line$
Next
Debug ""
Next
EndProcedure
Calendar(2024)
Last edited by Little John on Fri Dec 29, 2023 6:40 pm, edited 1 time in total.
-
- Addict
- Posts: 4775
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: DateEx: Extended Date library
New version 1.30, 2023-12-29
Fixed
Fixed
- Bug in Procedure AddDateQ() with #PB_Date_Month
- Bug in Procedure DateDiff()
- Procedure Julian2PureDate() now does bounds checking.
- additional error codes for more precise information
- cosmetic changes
- improved some comments
- support for Mac OS
- some additional examples
- demo program how to easily create an annual overview calendar (see previous post)
-
- User
- Posts: 24
- Joined: Wed Jul 06, 2022 3:49 pm
Re: DateEx: Extended Date library
Thank you very much!
Runs Perfect! on macOS (intel)
Tested version 1.30, 2023-12-29
Also tested Demo Program
on:
PureBasic 6.04 LTS - C Backend (MacOS X - x64)
IDE build on 12/14/2023 [16:02] by fred
Branch: v6.04 Revision: 1fa823f13c64
MacBook Pro 16-inch, 2019
2.3 GHz 8-Core Intel Core i9
16GB 2667 MHz DDR4
Storage 1TB
macOS Ventura 13.6.3 (22G436)
Runs Perfect! on macOS (intel)
Tested version 1.30, 2023-12-29
Also tested Demo Program
on:
PureBasic 6.04 LTS - C Backend (MacOS X - x64)
IDE build on 12/14/2023 [16:02] by fred
Branch: v6.04 Revision: 1fa823f13c64
MacBook Pro 16-inch, 2019
2.3 GHz 8-Core Intel Core i9
16GB 2667 MHz DDR4
Storage 1TB
macOS Ventura 13.6.3 (22G436)