My first question would be: How would you calculate it in any case or at all? What options exist?
Is there a web service you could call? (easy to do in FM)
Is there some type of data you could import from NOAA or similar (easy to do in FM).
While FM encourages you to "jump in and start coding", it's really easier if you map out what you want to do first (line up data sources) and then figure out how to map it to FileMaker.
For Java, for example, I quickly found a library that takes LAT/LON and will give you sunrise and sunset times:
I would imagine that in some way, FM or FM Plug-in, Web Service call from FM, etc., you'd have to have code similar (or call code similar) to the following Java example:
Location location = new Location("39.9522222", "-75.1641667");
// Pass the time zone display here in the second parameter.
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "America/New_York");
If it were me, I'd download the source code of any of these libraries and just see how they do the lookup. Then, you could choose another environment that may better suit you or the application. I would really prefer to have the data locally, if possible.
Please post back with your approach so we can see how you did it, OK?
You can load the library and your parameters in WebViewer with data url and it should be iOS compatible.
Nice! Cool idea.
What I would probably do is make a call to a REST web service method I would put on my server. FileMaker makes it so easy to call via GET or POST, I use this all the time.
(assuming having local NOAA/other data isn't a viable alternative.)
Just realised, that the link I posted is for a NODE.JS module with three dependencies. It is still doable, but not that easy - you would have to package the whole thing into one script (I think bower in NODE.JS can do this)
An alternative would be to look for an algorithm like this one - Sunrise/Sunset Algorithm and implement it in FIleMaker, which I think that OP was asking, before we all went our fancy ways.
You’ll need to select a year and a city, which makes sense as the times differ based on timezone, as Beverly mentions. Unfortunately, I didn’t find a way to scrape (via Import from URL) or an RSS feed so I copied/pasted the table and wrote a script that loops through and creates the records. I then add all this data (I did 10 years worth) to the product in a reference table.
Having this reference table is very useful for service industries where the service charge rate is different for daytime and nighttime.
Having taken some basic astronomy classes, I believe that you can calculate this based on latitude and longitude, and day of the year. That would be the ideal way and could be one custom function if you did all the maths yourself.
Yes! look at nicolai's reply with the link. It may take work, but probably is "do-able" with variables and functions in FM. I don't know if I'd create custom function, if script would do.
Using that detailed well-documented algorithm, you could implement this in just about any way you want.
I bookmarked that link you included for future reference.
I love this forum. Sometimes you come up with an absolutely crazy idea, post it and there will be three people immediately saying: "Yep, done that! Here is a sample file"
The things I additionally like about this forum are not only what you pointed out but that people are friendly, unpretentious, and immensely helpful.
To me, this is the most useful forum I've ever found.
In my mind, using a custom function is far more flexible than a script. For example, what if the logic is needed in a calculation? If it resides in a script, then you are looking at a schedule or trigger to update fields.
Also a custom function is more useful to modularly move between solutions or share with others!
I'm not sold on using CFs much.
How are they more flexible?
(My opinions below)
- You can't step through a CF to debug it.
- You can't loop other than recursively.
- There isn't as much code assist when typing.
- You tend to have to use LET() for just about everything beyond super short stuff.
- CFs feel to me more like a Custom Calculation than a Custom Function.
But, the advantage of CFs from my perspective is that you can access them when you do calculations, which is nice. Also, they accept multiple parameters easily - shame on FM for not having multiple parameter in scripts by version 14 (yes, there are workarounds, but come on).
It probably comes as no surprise where I would, especially given the nice code assists in version 14, opt for a scripting approach to most things requiring more than a couple lines.
I'm sure others disagree, but that's OK.
Bottom line is that it's great the FM has all these different ways to do stuff.