×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Next Friday Function
4

Next Friday Function

Next Friday Function

(OP)
Just a bit of old code... to give you the date of the next Friday.

CODE

FUNCTION NEXTFRIDAY
	PARAMETERS m.MYDATE
	PRIVATE m.MYDATE
	IF PCOUNT() < 1
		m.MYDATE = DATE()
	ENDIF
	m.MYDATE = m.MYDATE + (6-(DOW(m.MYDATE,1)-(INT(DOW(m.MYDATE,1)/6)*7)))
	RETURN(m.MYDATE) 

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

Works for me, Griff.

One tiny improvement:

Instead of this:

CODE -->

PARAMETERS m.MYDATE
PRIVATE m.MYDATE 

you could do this:

CODE -->

LPARAMETERS m.MYDATE 

saving a whole line of code.

I would also prefer to lose the mdots on the left of the assignment statements, but I won't open that can of worms again.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Next Friday Function

(OP)
Hi Mike L,

Yes, I have never really adopted the lparameters approach, and here it is more appropriate than my 'long hand' happy shades

The m.dots on the left side may not be necessary, because you can't assign to a field, obviously enough, but I'm happy
with that omission to improve clarity (in my opinion) and the habit of using them reduces the chances of a typing error
creeping in.

Hi Mike Y

I do use Hungarian notation, but only where I am maintaining code developed by someone else - for example I sometimes
customise WestWind utilities and I use the same notation Rick does, again not necessary - but I think it is better
to use 'the same pen' as the originator and not faff about with chalk on his finely crafted calligraphy!

Edit
Of course, these days I'm pretty confident the only person maintaining my code is likely myself... so it's only
public if I present it here.

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

Use the right value for DOW and you can reduce the math very much.

Chriss

RE: Next Friday Function

(OP)
Hi Chriss

Are you thinking if I used the DOW pointing to a Friday base?

CODE

DOW(m.MYDATE,6) 

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

Maybe that or 7. I'm just sure, but there's a way the 1...7 range of DOW is exactly opposite of the 0...6 sequence you actually need, 0 for when you're at Friday already. Well, unless you would add 7 for next Friday on a Friday. Anyway you like it, you can get date+7-dow(date,n) or date+8-dow(date,n) to work as you need. No need for a portion INT(DOW(m.MYDATE,1)/6)*7 as a correction term.

Chriss

RE: Next Friday Function

(OP)
I can see how using Friday in DOW() as a base for calculating the next Friday ought to simplify the math, but the clue is in the name.

Next Friday is not equal to today, it has to be at least a day away, otherwise it would be nearest Friday happy shades

I started this thread for two reasons, firstly as MY kinda alluded to, in most cases iterating through a loop is probably
less efficient to 'doing the math' - I was reading something recently where even branching on the ELSE was considered
'inferior' - maybe, maybe not. Secondly I wanted to demonstrate that a discussion often generates something actually better
which might be unexpected. NEXTFRIDAY() is nearly forty years old, it isn't pretty, perhaps not as efficient as three people
can make it, but it is - this is key - an example of the shoulders on which we all stand.

We stand on trillions of lines of other peoples code, good, bad or WTF.

I'm pretty happy with that... but I am most certainly going to try and get my grey cells to follow Chris's advice.
Trouble is, they are ... sorry, who are you?

Thank you gentlemen, ahem, people, have a nice evening

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

There's a much better way to do this, because not only the number of function calls matters, also their cost. I already have seen mathematiicians argue with just the number of operatons for algortihms and fail in their estimation because they know very little about operator costs. And they should know once they enter the realm of computer science.

Anyway, it was never fruitful to show you something, I'll just leave that here and don't bother.

Chriss

RE: Next Friday Function

(OP)
Taking the various comments on board, save the unnecessary assignment to an m.dot variable, this would be
the likely simplification of NextFriday()

CODE

FUNCTION NEXTFRIDAY
	LPARAMETERS m.MYDATE
	IF PCOUNT() < 1
		m.MYDATE = DATE()
	ENDIF
	** use DOW(x,6) for Friday based return value
	m.MYDATE = m.MYDATE + (8-DOW(m.MYDATE,6))
	
	RETURN(m.MYDATE) 

Faster, more readable, easily modified for NextMonday() etc.



Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

(OP)
For purists perhaps happy shades

CODE

FUNCTION NEXTFRIDAY
	LPARAMETERS m.MYDATE
	m.MYDATE = IIF(PCOUNT() < 1, DATE(), m.MYDATE)
	** use DOW(x,6) for Friday based return value
	RETURN(m.MYDATE + (8-DOW(m.MYDATE,6)))
ENDFUNC 

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

EVL is also helpful. Often makes unnecessary to look into PCOUNT anymore, as VFP sets not passed-in parameters to .F. and .F. is empty.
I guess I'm alone in thinking the initial value of a LOCAL var or a parameter should be .NULL., anyway.
I get your point about next, Griff. Just even VFP itself is using REPLACE NEXT 1 for the record itself and not really the next one. I don't assume that was programmed by a non-american. If it comes to language, there's a lot to say about English and Americans about their own language usage, too, dialects and other quirks. Anyway, just spare any more comments on improvements.

Ah, yes, there is a nice read for the weekend, perhaps, by Tamar, about many Foxpro quirks, as well. https://pdfslide.net/documents/visual-foxpro-quirk...

Chriss

RE: Next Friday Function

(OP)
Hi Chris

So test for Empty() instead of pcount()?

CODE

m.MYDATE = IIF(EMPTY(m.MYDATE), DATE(), m.MYDATE) 

With a local parameter (lParameter) that would work, would it with a private? Not that it is relevant in this example!

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

Quote (Chriss)

there is a nice read for the weekend, perhaps, by Tamar, about many Foxpro quirks, as well. https://pdfslide.net/documents/visual-foxpro-quirk...

Thanks for posting that link, Chris. It's something we should all take the time to read.

For the same article in a possibly more user-friendly format, I suggest http://www.tomorrowssolutionsllc.com/ConferenceSes.... The text is identical, but it doesn't have the formatting issues that I see on the PDFSlide site (which might be specific to my system / browser).

While you are at www.tomorrowssolutionsllc.com, take a look at some of Tamar's other articles and conference papers. There's a lot of good stuff there.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Next Friday Function

Griff, not IIF with EMPTY(), EVL(). m.MyDate= EVL(m.MyDate,DATE()). Unless you absolutely want to be backward compatible, I don't see a benefit of that when I have my project being a VFP9 project, though, there only is a benefit of backward compatible programming to a framework or libaray you absolutely want to use in older projects.

If you don't pass something to a private paramater, it also becomes .F., that's simple to see just doing it:

CODE

test()

Function test()
   Parameters p1
   ? p1 

Chriss

RE: Next Friday Function

(OP)
Yes Chris, I can see how that would work.

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

(OP)
I think Chris suggested either 6 or 7, and gave rough examples.

I chose to simplify it to dow(,6) because it was then clear, to me at least, that NextSaturday(), NextTuesday() etc.
would only require modifying that index - maybe ,7) would too - but I haven't tested that.

No disrespect was intended.

As coders we all rely on the people who came before us, who built the OS we work on, the compilers that made that possible,
the people who developed dBase, Fox, Delphi, C, assemblers...

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: Next Friday Function

Thinking in the wrong direction, not exhausting possibilities.

Chriss

RE: Next Friday Function

It's simple math, it's not even really special math, just the four basic mathematical operations, in which I include modulo, there's nothing to be proud about. I did this in school, calculating julian day number is not hard and faster done than SYS(11) plus string conversion. And then date differences and DOW also become two derived results from the same value, whereas your code is repetitive in that aspect, as you just never thought about skipping inbuilt functions and doing all math yourself. That's were you actually fail to impress me and I have to give it back to you, that I am astonished it's still not obvious to you. One more point about it is that it's not even halfways genius to find Julian day numbers useful when Unix already had the idea to make it the norm for dates to simply be a number of days or seconds or now even nanoseconds from a root datetime. You can do all the essential calculations in it simpler, there's no art nor craftsmanship in this, it's pure knowledge that even preexisted computer science.

I actually already posted details about how you go about this, just not in this forum. Anyway, why do you even ask? You don't need anybody's enlightenment anyway.
You're sketching scenarios that are not true, that hass actually again become quite unbearable.

Chriss

RE: Next Friday Function

Just want to point out that I did NOT give permission for PDFSLIDE to share my documents. I'm about to report the violation of my copyright.

Please if you're sharing my papers, do so from my website: www.tomorrowssolutionsllc.com

Thanks,
Tamar

RE: Next Friday Function

> Then why hasn't anyone come up with this version before?

Er ... I presume you mean why has no-one in this forum come up with this version, as the basic algorithm is not exactly new? I've certainly seen it in the past (e.g https://www.theinformationlab.co.uk/2017/05/22/cal...)

RE: Next Friday Function

Tamar (and others),

I just noticed that PDFSLIDE has also taken one of my articles without permission. Does it survive my stealing other people's work? Please do report them, and let us know how you get on. I will do the same.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Next Friday Function

They had 4 or 5 of mine. I reported them all. Haven't heard anything from them and at least this one is still up. I'll give it another day or two and then I'll figure out another way to go after them.

I hate these sites that let just another post a document and don't require them to prove they have IP rights. ScribD had a whole bunch of mine a while back. I actually talked to a lawyer about it, but the feeling was that there wasn't provable harm, so hard to succeed. I check back there periodically to see whether there's more.

Tamar

RE: Next Friday Function

Tamar,

I've faced this situation before. If a polite email to the company doesn't work, my next step has been to contact the abuse administrator, either of the site itself or its hosting company (if any). Every reputable publishing platform or hosting company should have an abuse administrator. You can find their contact details by first determining the site's IP address (for example, by using ping in a command window), and then doing a WhoIs search on that address.

If the offending site is based in the US (but there is often no way of knowing that), you can also take action under the Digital Millennium Copyright Act (DMCA). I've considered doing that a couple of times, but so far it hasn't been necessary.

I hope the above info will be of some help to others who face this situation.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Next Friday Function

Tamar,

It looks like that particular article has now been removed from PDFSLIDE. But I also noticed a copy of the same article on another site. I won't paste the URL directly into this post, as I don't want to give it the benefit of a link, but it is essentially "fdocuments" followed by ".net" adnd then "/document/dev180-visual-foxpro-quirks-tamar-e-foxprodev180-visual-foxpro-quirks-by-tamar" and finally ".html"

I wonder how many more of these pirate sites exist.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Next Friday Function

Yeah, this site removed my articles. (I reported through their mechanism.) But it's a constant fight. And even with the reputable sites, if you have stuff by more than one author, it's a real hassle to remove because you have to assert that you have the permission of all authors.

The one you just sent me to had more of mine, but didn't seem to be monetized. Those are the ones that make me angriest--them charging people to see my work without paying me.

Tamar

RE: Next Friday Function

Sorry Tamar, it seemed to me a site you use to share session slides publicly.


Mike, you seem to be in a mood for accusations, to say it mildly.

Tamar has very good reasons to be upset as pdfslides advertises with content they just grab from anywhere. They are even as pretending fair use as they point out DMCA. Very clearly just profiting from anyone not caring about earning without much own involvement other than crawling the web.

Chriss

RE: Next Friday Function

Another attempt:

CODE -->

FUNCTION NextFriday
LPARAMETERS dDate
RETURN m.dDate + IIF(DOW(m.dDate)<6,6,13)-DOW(m.dDate) 

Steve

RE: Next Friday Function

>Well, let's break down the example you're so proud of.

I'm not being proud of anything. No idea where you get that idea from. I was merely pointing out that this is not a new algorithm, and providing evidence of that. Sure, your particular implemention differs, but it was unclear that that is all you were claiming.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close