Hi everyone! Yes, I'm the Salty Dog page, and this library is an attempt to replicate what's in C#'s static classes, which are really powerful to have around.
The STRING one is mostly complete but I just got started on the DATETIME and it's definitely a work in progress. To stay on top of it, you can click the "Watch" button on the GitHub page and you'll get notifications whenever a new commit happens (I've done a lot just in the last few days as I've been using this library as I work on another class to validate JWTs in FoxPro.
I really like all the feedback! Another thing you can do is submit an issue on the GitHub page itself (and then get notified when it's handled) or better yet, clone the repo and make some contributions! :)
Eric
On Fri, May 18, 2018 at 1:26 PM, Jürgen Wondzinski juergen@wondzinski.de wrote:
This FirstDayOfQuarter and siblings is much easier to do:
FUNCTION GoQuarter(dDate, cValue)
- "L" = (L)ast day of dDate's Quarter
- "F" = (F)irst day of dDate's Quarter
- "N" = first day of (n)ext dDate's Quarter
- "P" = first day of (p)previous dDate's Quarter
cValue = EVL(cValue, "F") LOCAL dResult DO CASE CASE cValue = "L" dResult = GOMONTH(dDate,(CEILING(MONTH( dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate) CASE cValue = "F" dResult = GOMONTH(dDate,(CEILING(MONTH( dDate)/3)*3)-MONTH(dDate)-2)-DAY(dDate)+1 CASE cValue = "N" dResult = GOMONTH(dDate,(CEILING(MONTH( dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate)+1 CASE cValue = "P" dResult = GOMONTH(dDate,(CEILING(MONTH( dDate)/3)*3)-MONTH(dDate)-5)-DAY(dDate)+1 ENDCASE RETURN dResult
wOOdy
"*´¨) ¸.·´¸.·*´¨) ¸.·*¨) (¸.·´. (¸.·` * .·`.Visual FoxPro: It's magic ! (¸.·``··*
-----Ursprüngliche Nachricht----- Von: ProFox profox-bounces@leafe.com Im Auftrag von Frank Cazabon Gesendet: Freitag, 18. Mai 2018 18:41 An: profox@leafe.com Betreff: Re: Fun with date calculations in VFP
Lots of spare time today so some hopefully constructive criticism: :)
I would redo some of that code to get away from CTOD() as that will fail depending on SET STRICTDATE and if SET DATE is anything besides MDY.
I have a feeling that your first day of week and last day of week will be incorrect in situations with SET FDOW.
I think PARAMETERS() is also advised against and PCOUNT() is better.
I would also move each function into its own program.
For example FirstDayOfQuarter.prg would be:
LPARAMETERS tdDate
LOCAL lnMonth as Integer, lnYear as Integer, ldDate as Date if PCOUNT()=0 then m.tdDate = date() endif m.lnYear = YEAR(m.tdDate) m.lnMonth = MONTH(m.tdDate) DO CASE CASE BETWEEN(m.lnMonth,1,3) m.ldDate = DATE(m.lnYear, 1, 1) CASE BETWEEN(m.lnMonth,4,6) m.ldDate = DATE(m.lnYear, 4, 1) CASE BETWEEN(m.lnMonth,7,9) m.ldDate = DATE(m.lnYear, 7, 1) OTHERWISE && CASE BETWEEN(m.lnMonth,10,12) m.ldDate = DATE(m.lnYear, 10, 1) ENDCASE return ldDateFrank.
[excessive quoting removed by server]