How could this be implemented?
Thank you :)
How about you start and we will help?
How about you start and we will help?
I am stuck. I don't know how to start. I know that it is related to the longitude and latitude positions and the regions of where it is dark and bright. I do not know what math is behind it though.
Just FYI, this is for a major project I am developing where I will be classifying data according to time of day.
Then you need to define the problem a little better - what is the input, what is the expected output?
Then you need to define the problem a little better - what is the input, what is the expected output?
Input:
- The current date which includes the day, month, and the year and hours/minutes/seconds.
- Location's the longitude/latitude.
Output: Morning/Afternoon/Sunset/Night status is returned.
Again just to be clear, you want to know the Morning/Night status like 12:00 is noon, 22:00 is night time, or you want to know the light times where you need to consider things like the north poll, where there can be light for days.
Again just to be clear, you want to know the Morning/Night status like 12:00 is noon, 22:00 is night time, or you want to know the light times where you need to consider things like the north poll, where there can be light for days.
Well, I need to divide it based on the light times. Morning and night alone are not enough. Different locations have different lengths of sunlight and darkness- I need to consider this if I want it to work in any city.
Well, then you will have to provide the formulas to how to calculate such a thing (not the code, just the formulas), and then we will try to implement it into code.
If you don't have any formulas to start with, I suggest you start off by looking up some things:
- At which latitude is the north/south polar circle (beyond this one there's midnight sun 24 hours a day during a period in summer and dark 24 hours a day during a period in winter)
- When is the first/last day of midnight sun and when is the first/last day of total darkness
This data should be sufficient. Now, since earth is a sphere that is slightly tilted, spinning around its own axis and travelling in a "spherical" path around the sun, I suggest you start off working with some sine patterns.
(Tip: Start by describing the suns motion over the globe with the sum of two sine curves, one with the period of one year, and one with the period of 24 hours.)
Good luck to you!
Emil Olofsson
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.