jaybizzle/php-seasons 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jaybizzle/php-seasons

Composer 安装命令:

composer require jaybizzle/php-seasons

包简介

A small utility class that returns the season from a given date.

README 文档

README

Tests Total Downloads MIT Version

A lightweight PHP utility class that returns the season from a given date. Supports meteorological and astronomical season calculations, northern and southern hemispheres, and custom season names for translations.

Installation

composer require jaybizzle/php-seasons

Quick Start

use Jaybizzle\Seasons;

// Get the current season
$season = new Seasons;
$season->season(); // e.g. "Spring"

// Get season for a specific date
$season->season('1st June'); // "Summer"

// Static convenience methods
Seasons::now();          // e.g. "Spring"
Seasons::for('1st June'); // "Summer"

Season Calculation Methods

By default, seasons are calculated using meteorological boundaries based on whole calendar months:

Season Months
Winter December, January, February
Spring March, April, May
Summer June, July, August
Autumn September, October, November

Astronomical Seasons

You can switch to astronomical season boundaries, which use approximate equinox and solstice dates:

Season Approximate Dates
Spring March 20 - June 20
Summer June 21 - September 22
Autumn September 23 - December 21
Winter December 22 - March 19
$season = new Seasons;

$season->season('March 19');                // "Winter" (meteorological: March = Spring)
$season->astronomical()->season('March 19'); // "Winter" (astronomical: before equinox)
$season->astronomical()->season('March 21'); // "Spring" (astronomical: after equinox)

The astronomical calculation adjusts automatically for leap years.

Southern Hemisphere

Seasons in the southern hemisphere are reversed. Use the southern() method to get the correct season:

$season = new Seasons;

$season->season('July');              // "Summer"
$season->southern()->season('July');  // "Winter"

This works with astronomical mode too:

$season->astronomical()->southern()->season('March 25'); // "Autumn"

Immutable Fluent API

The astronomical() and southern() methods return a new instance, leaving the original unchanged. This means you can safely reuse the same base instance:

$season = new Seasons;

$northern = $season->season('July');              // "Summer"
$southern = $season->southern()->season('July');   // "Winter"
$original = $season->season('July');               // Still "Summer"

Month Ranges

Get the month numbers that belong to a given season:

$season = new Seasons;

$season->monthRange('Winter'); // [12, 1, 2]
$season->monthRange('Summer'); // [6, 7, 8]

// Southern hemisphere month ranges
$season->southern()->monthRange('Summer'); // [12, 1, 2]

Translations

Pass an array of four season names to the constructor in the order: winter, spring, summer, autumn. All output will use your custom names:

// French
$season = new Seasons(['Hiver', 'Printemps', 'Été', 'Automne']);
$season->season('June');        // "Été"
$season->season('January');     // "Hiver"
$season->monthRange('Été');     // [6, 7, 8]

// German
$season = new Seasons(['Winter', 'Frühling', 'Sommer', 'Herbst']);
$season->season('October');     // "Herbst"

// Japanese
$season = new Seasons(['', '', '', '']);
$season->season('April');       // "春"

Translations work with all features including southern(), astronomical(), and monthRange():

$french = new Seasons(['Hiver', 'Printemps', 'Été', 'Automne']);
$french->southern()->season('June');                // "Hiver"
$french->astronomical()->season('March 21');        // "Printemps"

The static methods also accept translations:

Seasons::for('June', ['Hiver', 'Printemps', 'Été', 'Automne']); // "Été"
Seasons::now(['Hiver', 'Printemps', 'Été', 'Automne']);          // e.g. "Printemps"

Date Formats

Any date string parsable by PHP's strtotime() is accepted:

$season = new Seasons;

$season->season('June');               // "Summer"
$season->season('1st October 2016');   // "Autumn"
$season->season('2024-12-25');         // "Winter"
$season->season('next Friday');        // depends on current date

An Exception is thrown if the date string cannot be parsed.

API Reference

Method Returns Description
new Seasons(?array $names) Seasons Create instance, optionally with custom season names
season(?string $date) string Get season for date (or current date if null)
astronomical() Seasons New instance using astronomical boundaries
southern() Seasons New instance using southern hemisphere
monthRange(string $season) array Get month numbers for a season
Seasons::now(?array $names) string Static: get current season
Seasons::for(string $date, ?array $names) string Static: get season for a date

Constants

Seasons::SEASON_WINTER // "Winter"
Seasons::SEASON_SPRING // "Spring"
Seasons::SEASON_SUMMER // "Summer"
Seasons::SEASON_AUTUMN // "Autumn"

License

MIT

jaybizzle/php-seasons 适用场景与选型建议

jaybizzle/php-seasons 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.6k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「date」 「season」 「seasons」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jaybizzle/php-seasons 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jaybizzle/php-seasons 我们能提供哪些服务?
定制开发 / 二次开发

基于 jaybizzle/php-seasons 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 19.6k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-12