Thinking about Time

One of my projects over the last few weeks was to improve my code related to time and location.

Part of going into this code, aside from normally doing the rounds of updates & bugfixes on my projects was because WordPress introduced some new functions to better handle date and time functionality. I backported them into my code and adopted them and added several based on the new methodology.

The time handling functionality in my Simple Location plugin started in 2015. I was in a timezone 7 hours later than home, and didn’t like my posts were showing 3AM…it completely changed the context of the post. So, I not only added to my site the timezone, but I wrote the code to transform the post’s time based on a per post setting that would be derived from the post’s location(functionality provided by the plugin already).

If you look at my recent posts, you’d see this adjustment, as I just fixed a few bugs in it. My California posts say PDT, as opposed to my normal EDT.

I also added a widget to my site that can show the current time where I am.

How I can take this further? So, I spent time at IWC NYC learning about sunrise and sunset. PHP, the language WordPress is written in, has built in functions for calculating sunrise and sunset…but it turns out that they don’t properly factor in elevation…which means that the visible sunrise and sunset could be off by as much as 2 minutes. My code does actually derive elevation from an API, so it can make the adjustment.

Being that type of astronomy and math is not my area of expertise, I had to do some reading. And now, with some modifications, my code is now a bit more accurate.

So, why is sunrise and sunset important? I wouldn’t mind my site changing based on time day, but it is mostly that in the Jewish calendar, observances begin at sunset, not midnight. So, I want to be able to account for that.

There are some plugins for calculations, but not with the location based goal I have…it is usually to show the start of holidays and such at a specific location, not to follow me around where I am. So, I want to incorporate work off of this. It makes for an interesting challenge.

There is always more to do. A new Simple Location should be out in the coming days/week and I’ll post about the features.

David Shanske

My day job is in training for an airline. I also develop Indieweb WordPress plugins so that others can take control of their online identity.

Leave a Reply

Your email address will not be published. Required fields are marked *