Re: DateEx: Extended Date library
Posted: Tue Aug 01, 2023 4:07 pm
Wow, this is great! Thanks Little John!!!
http://www.purebasic.com
https://www.purebasic.fr/english/
Thanks for your kind words.
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 ?
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.![]()
Code: Select all
Assert(DateQ() = Date())
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())
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!)
Code: Select all
405 CompilerCase #PB_OS_MacOS
406 g_Error = #Err_OSnotSupported
407 ProcedureReturn -1
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!)
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
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.
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"
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)