How can WeekOfYear handle week start on a Monday?
Sent from miPhone
Hopefully, I'm misunderstanding your posting.
FMP seems to handle this situation correctly:
Do you have an example of what you mean?
In my view, FMP's date functions are poor and thus leave lots to be desired. FMP often give you incompatible values (like those from SQL) that don't work with FMP's own other date functions. Plus, FMP's date functions are "sparse", to say the least -- leaving the grunt work to you. Finally, there's no plug-in I know of (yet) for FMP that gives you a good date library.
Solution? Simple, create your own date functions in a micro-service using a modern programming language and then CALL that library from FMP!
(I've posted several examples of custom date functions using a miro-service with FMP here on the forum.)
Basic point: You should have a single unified way of figuring out what the week number is for a year regardless of which day it falls on. Getting consistent results (the correct result regardless of date) is the responsibility of the date function, not you, the programmer, to ponder which date function .... might work!
For 2018, the 1st of January was a Monday.
Python gets it right:
datetime.date(2018, 1, 1).isocalendar()
Java gets it right:
LocalDate date = LocalDate.of(2018, Month.JANUARY, 1);
WeekFields weekFields = WeekFields.of(Locale.getDefault());System.out.println("Week Number for date: " + date.get(weekFields.weekOfWeekBasedYear()));
I still might not be understanding the actual question you were asking, but if you have to ponder between two functions to get the right week of the year, then there is a problem.
Simple solution: Use a micro-service and a modern date API to get consistent results -- you can call from FMP using INSERT FROM URL. The micro-service returns the date (week number in this case) back to your FMP application.
Micro-services have other advantages....
1. Cross platform so the service can reside ... anywhere (Linux, Mac, Win). Local/WAN, Server, you name it.
2. Allows any application that can do a GET to use the service (Terminal, FMP, Firefox, Opera, Chrome, ....)
(POST or other HTTP verbs also supported.)
3. Is FREE. No expensive FMP-ONLY plug-in(s) needed. Install anywhere or everywhere. 1 user or 10,000 users...FREE.
4. Means there is no FMP plug-in installation and configuration for every copy of FMP you might have
5. Means no restrictive plug-in license agreements
6. Is extremely powerful (get the full power of Java + free third-party libraries like Apache and others.)
7. Puts you in charge of the service code. Not a third party.
8. Is ... FAST!
9. Externalize loops in Java to keep loops out of slow FMP scripts.
10. You could email the service JAR file to others and they could use it right away (assuming Java installed, etc.)
11. You could install the service as a regular Java web (REST) application (via WAR file install) to an existing application server like Tomcat.
12. Service programming uses tools that manage dependencies --- automatically!
13. Offers high abstraction. The caller of the micro-service doesn't need to know any details how the micro-service code works. Parameters can almost always be passed simply letting the micro-service handle translations or other messy details.
(Note: Most modern programming languages, including Java, support micro-services.)
HOPE THIS HELPS.
Yes but if you put date to 07/01/2018 you get 2
In Denmark we use calendar according to ISO 8601 where Monday is the first day of the week and not Sunday like in the US
If you use:
WeekOfYearFiscal ( date ; 2 )
... you will get the answer you are looking for.
For instance, if you have a date field called 'myDate' with value of '7/1/2018' (7th January 2018), then:
WeekOfYearFiscal ( myDate ; 2 )
will give you '1' as you expect.
- the '2' makes 'Monday' the first day of the week....
However, do read the notes here: FileMaker Pro 16 Help
Thanks for your answers as I now understand the function WeekOfYear is not usable
I made this example
So in the future I will use only WeekOfYearFiscal - 2
Did you see the "locale" portion of the Java example above?
WeekFields weekFields = WeekFields.of(Locale.getDefault());
That should handle where ever you are.
I can't help it if FMP gets it wrong.
Instead, just use a web service with TESTED industry standard date logic!
Simple. Free. Easy. Done!
Do you have good links and resources for creating or using a web service? I'd love to explore that more.
As you can see, here: Spark Framework: An expressive web framework for Kotlin and Java
It only takes a couple lines of code to create a Java-based web service after you set up your IDE and environment. There are several totally free Java IDEs (Eclipse being extremely popular, NetBeans, and Intelij (community edition), as examples).
In Python, creating a web service is simpler still. Check out links to Flask, as one source. Using a Python IDE, a Flask web service is actually a project type, meaning you can create a working "hello world" web service with no coding (just by creating a new project).
Python is nice too in that it's a simple, yet powerful, language with a HUGE and growing following. I read that MIT dumped whatever language they were using for CS students for Python.
The trick from FMP Is using INSERT FROM URL to reach the web service. POST, PUT, GET, ... No problem.
Once you get the Java IDE set up and create the basic maven project as described in the Spark link above, it's simple to add methods you can call from FMP. You can search for things you want to do online and add those to your web service project.
The web service can be local on your machine or on a file server or on the Internet. Functionally, as in "reaching the service", it really doesn't matter where it is...it's just a URL.
If you have questions, I will be more than happy to help.
Feel free to send me a PM or post here.
In my view, FMP's date functions are poor and thus leave lots to be desired.
In my view they are not, provided you treat dates as dates and don't consider text representations of dates to be dates and expect them to work as such. As a general rule, they work quite well and the calculations needed to manipulate date, time and timestamp data can be done effectively with simple arithmetic once you understand the basic unit on which the data type is based, days when it comes to dates and seconds when it comes to time and timestamps. Note that in this case, it was simply a matter of using the function designed for this purpose with the correct parameter.
I may be recalling past posts where fmpdude complained about FileMaker date short comings incorrectly and I apologize in advance if that's the case, but what I recall is that you've criticized FMP date handling because the result of ExecuteSQL querying the value of a date field returns a value of YYYY-MM-DD and FileMaker does not automatically recognize that result as a date. That seems a bit silly in my opinion, given that ExecuteSQL returns text, not values in other data types such as a true date. Given that the query results can represent the data from many different fields and records of all possible data types, that doesn't strike me as unreasonable. Plus, the manipulation needed to convert that text into a FileMaker date is very simple and one that I put into a custom function long ago just to save a few keystrokes when working with such values.
Awesome! You might mark an answer as correct or "Assumed Answered" (if more than one helpful reply).
Not just SQL stuff (where I would expect FMP, a multi-hundred dollar product, to have consistent date results -- to do that little extra so dates have the same format or give me functions where I can DEFINE the format as with other APIs. No CFs required -- me doing all the work -- and the configuration management associated across FMP installs, etc.)
To wit--if you want to see what a real date API looks like, check out the Java 8 Date API. I'm assuming, similar apologies if I'm mistaken, that you may not know what's readily available in nearly ubiquitous date APIs?
But, please put your energies toward the OP's question, not my opinions from using FMP for only 7 years. If you're happy with the date functions available in FMP, that's cool.
The OP has not replied to my postings so I'm signing off this thread now...
Retrieving data ...