11-25-2019 03:46 PM
Here is something simple that will allow anyone to set whatever they like for what day defines first week of year. Maybe it is overly complicated, maybe not.
I also left in the testability component so that if someone wants, for example, the first Wednesday as week one, they can back test it.
I needed this for much the same reasons. I didn't like the answers provided because I don't do .NET. I needed this for a labeling program that I wanted to auto-populate current year/week for manufacturing purposes.
11-26-2019 02:27 AM
Hi Eric,
your VI has some problems:
11-26-2019 09:03 AM - edited 11-26-2019 09:22 AM
Fair enough. I apologize that I let my American show by being oblivious that there are others in the world that may not use English as a primary language. (as this is just text, please note that this is a sincere comment, not being a jerk).
Here is a modified version of the same thing. I agree that I got a bit overzealous with making sure that I had a 2 digit year. I knew that, too, I was just doing it for the week and spaced out for a minute. Here is an updated version.
Sorry, had to edit a few times. First time it didn't add file. Second time, realized that the math changed from Sunday being a 0 value, as I had originally used, to Sunday being a 1, as LV uses in the Time Cluster.
I don't know how Goldberg-ian this solution is, it can probably be done better, but I found it simple and fairly clean compared to what I was seeing. However, I am not overly concerned about execution speed, or dealing with or integrating into a large, complicated project. If there is a better way of doing it, which I am almost certain that there is, I'm not offended if this is not the solution to use.
11-26-2019 09:32 AM
Rube Goldberg: https://en.wikipedia.org/wiki/Rube_Goldberg
"Goldberg is best known for his popular cartoons depicting complicated gadgets performing simple tasks in indirect, convoluted ways."
So, unnecessarily complex code. 🙂
/Y
11-26-2019 09:50 AM
Yes, I am painfully aware of Mr. Goldberg, and the cartoons depicting his "Miraculous" inventions. It would not be the first time that my code has been compared to his style of coding, sadly.
Do you think that what I currently have is overly complicated? Why? I have been playing in LV for quite some time, but it has never been my full time occupation. As a result I have years of experience, but only months of actual knowledge. Any input is appreciated.
11-26-2019 10:26 AM
11-26-2019 02:40 PM - edited 11-26-2019 02:41 PM
Ok. Here is something a little more cleaned up. Also, I am not doing something as convoluted as that ISO standard. That is a lot of math just to find a week of the year. I'm sure it makes perfect sense for some applications, I just have not been involved with any of those applications. I just needed to make my week codes match an online calendar that is used at our company for figuring out week of the year. The standard I was matching is that the week 1 is defined with the first Thursday of January. I think that for something simple as that, this isn't a bad application. Especially now that you have made me look at it more closely and make it more streamlined. At least I think it is. I could be wrong. I did, at least, take out the English in the code. Thank you for pointing that out. I will try and remember that next time I am posting something that I want to advertise as ubiquitous.
I know that I would not have done what you did if I had to do the standard that you built. I would have hacked at it a bit more and it would have been a bit clunky and Goldberg-y. The joys of learning how to effectively program. 🙂
11-20-2024 01:17 PM
Adding snippet that list all (LabVIEW) yearly week numbers with weekly start and end time ranges, adjusted for DST and selectable day of week start (defaults to Sunday at midnight).
Note: LabVIEW's week numbers (00-53) are sometimes offset from commercial week numbers like Calendar-365 (01-52).