jiri.jozif/datesuninfo
Composer 安装命令:
composer require jiri.jozif/datesuninfo
包简介
PHP library for calculating sunrise and sunset
README 文档
README
PHP library for calculating Sunrise, Sunset and Sun transit
A more accurate replacement for the PHP function date_sun_info(). In addition, the library provides extra values and functions.
Installation
This library is available for use with Composer — add it to your project by running:
$ composer require jiri.jozif/datesuninfo
Usage
The replacement function is simple, instead of
$dsi = date_sun_info($timestamp, $latitude, $longitude);
you type
use JiriJozif\DateSunInfo\DateSunInfo;
$dsi = DateSunInfo::get($timestamp, $latitude, $longitude);
The class returns the same data as date_sun_info(), but with more accurate values.
Static class method DateSunInfo::get with up to three required parameters; the fourth is optional:
- $timestamp (int): The Unix timestamp.
- $latitude (float): The latitude of the location in degrees.
- $longitude (float): The longitude of the location in degrees.
- $asObject (bool, optional): The default output is an array. If the fourth argument asObject is set to
true, the output will be an object. Example:
$dsi = DateSunInfo::get($timestamp, $latitude, $longitude, true);
echo date('H:i', $dsi->sunrise);
You can then use the following methods:
DateSunInfo::get(int $timestamp, float $latitude, float $longitude, ?bool $asObject): Returns the same output as the date_sun_info() function, but with more accurate values.DateSunInfo::getRiset(int $timestamp, float $latitude, float $longitude, ?bool $asObject): Shorter output, returning only the sunset, sunrise, and sun transit times.DateSunInfo::getAll(int $timestamp, float $latitude, float $longitude, ?bool $asObject): Extended output, returning the azimuth of sunset and sunrise, as well as the height of the sun transit.DateSunInfo::getPosition(int $timestamp, ?float $latitude, ?float $longitude, ?bool $asObject): Returns the sun's coordinates for the given timestamp. If latitude and longitude are specified, it also returns the horizon coordinates.DateSunInfo::hh_mm(int $timestamp): Returns the rounded time (to the nearest minute) as a string in hh:mm format, or "**:**" if the sun is continuously above the horizon, or "--:--" if the sun is continuously below the horizon.DateSunInfo::hh_mm_ss(int $timestamp): Returns the time as a string in hh:mm:ss format, or "**:**:**" if the sun is continuously above the horizon, or "--:--:--" if the sun is continuously below the horizon.
Return Values:
sunrise: The timestamp of the sunrise ortrueis Sun continuously above horizon orfalseif Sun continuously below horizon.sunset: The timestamp of the sunset ortrueis Sun continuously above horizon orfalseif Sun continuously below horizon.transit: The timestamp when the Sun is at its zenith, i.e. has reached its topmost point.civil_twilight_begin: The start of the civil dawn (The Sun is 6° below the horizon). It ends at sunrise.civil_twilight_end: The end of the civil dusk (The Sun is 6° below the horizon). It starts at sunset.nautical_twilight_begin: The start of the nautical dawn (The Sun is 12° below the horizon). It ends at civil_twilight_begin.nautical_twilight_end: The end of the nautical dusk (The Sun is 12° below the horizon). It starts at civil_twilight_end.astronomical_twilight_begin: The start of the astronomical dawn (The Sun is 18° below the horizon). It ends at nautical_twilight_begin.astronomical_twilight_end: The end of the astronomical dusk (The Sun is 18° below the horizon). It starts at nautical_twilight_end.
Extended output from method DateSunInfo::getAll():
sunrise_azimuth: The azimuth of the sunrise in degree.sunset_azimuth: The azimuth of the sunset in degree.transit_height: The height of the transit in degree.lowest_height: The lowest height of the Sun in the sky, in degrees, occurs on the opposite side as the transit.
Output from method DateSunInfo::getPosition():
RA: Right Ascension in degree.Dec: Declination in degree.Lon: Ecliptic longitude in degree.R: Distance from Earth in AU.h: Horizontal coordinate system, height (altitude) above horizon in degree (only if latitude and longitude were entered).Az: Horizontal coordinate system, azimuth in degree (only if latitude and longitude were entered).
Example
<?php use JiriJozif\DateSunInfo\DateSunInfo; $dsi = DateSunInfo::getRiset(time(), 51.48, 0.0); //Royal Observatory, Greenwich echo "The Sun rises today at ", DateSunInfo::hh_mm($dsi['sunrise']), " and sets at ", DateSunInfo::hh_mm($dsi['sunset']);
Options
You can modify the default values using the DateSunInfo::setOptions() method. For example, you can set the height of the observer above the environment or enable additional dawn and dusk calculations.
DateSunInfo::setOptions(array $options): Modifies the default values, where options is:'height' => float $height: Height of the observer above the environment in meters.'altitude' => float $altitude: The default angle for finding sunrise or sunset is -0.833° below the horizon. This is the sum of the refraction at the horizon (34') and the apparent radius of the Sun (16'). It can be modified here.'topographic_azimuth' => bool $type_azimuth: Iftrue, the class uses the topographic azimuth (North = 0°, East = 90°, South = 180°, West = 270°). Iffalse, the class uses the astronomical azimuth (North = 180°, East = 270°, South = 0°, West = 90°).'twilight' => [float $angle => [string $begin_name, string $end_name]]: The definition of other twilights.
Example
<?php use JiriJozif\DateSunInfo\DateSunInfo; DateSunInfo::setOptions([ 'height' => 300, // Observer on Eiffel tower 'topographic_azimuth' => false, // Enable astronomical azimuth 'altitude' => -0.583, // Swedish national alamancs 'twilight' => [ 10 => ['golden_hour_end', 'golden_hour_begin'], // For photographer -15 => ['amateur_astronomical_twilight_begin', 'amateur_astronomical_twilight_end'] // For amateur astronomer ] ]);
Help
If you have any questions, feel free to contact me at jiri.jozif@gmail.com.
jiri.jozif/datesuninfo 适用场景与选型建议
jiri.jozif/datesuninfo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「set」 「transit」 「astronomy」 「sun」 「rise」 「azimuth」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jiri.jozif/datesuninfo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jiri.jozif/datesuninfo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jiri.jozif/datesuninfo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple, immutable data structures
Baum is an implementation of the Nested Set pattern for Eloquent models.
A file uploader with support for validation, image transformation and remote transportation.
A useful set of HTML and Form macros with css and js made for bootstrap
PHP UPS API
Calculate sun position, sunlight phases, moon position and lunar phase.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-10
