Today I published my code for finding the timezone of a specific location as a standalone library.
Previously it was part of my Atlas web service, which provides various functions such as generating static maps, geocoding, and looking up weather information. I started wanting specifically the function of finding the timezone for a given location in other projects such as XRay and Quill. This allows me to do things like set the proper timezone of an Instagram photo based on the photo's location, since Instagram dates are always set to UTC.
A few days ago I copied the code from Atlas to XRay, with a "TODO" reminding me to publish it as a library soon. Today I wanted to use it in Quill, and I decided that three copies of the code floating around would not be a good idea. Time to publish as a library!
Luckily this code was relatively small and already in only one file. Here's what it took to publish it as a library.
- Created a new GitHub repo for the library
- Wrote a README with a description and sample code
- Chose a license for the project, and added the license file and CONTRIBUTING.md file
- Copied the code from Atlas to the new repository, and verified that it had no additional dependencies
- Created composer.json describing the library to prepare for publishing on Packagist
- Committed and tagged version 0.1.0
- Updated Atlas and XRay code to use this library, removing the old code from the projects
- Updated XRay composer.json to load the library directly from GitHub, since it is not yet published on Packagist (example config)
- Tested that XRay can use the new library
- Created a new package on Packagist, and configured the GitHub service hook so that it's automatically updated when I push to GitHub
- Updated XRay and Atlas' composer.json to load the new library from Packagist
Hopefully this will be useful to others!