承接 dcaswel/time-converter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dcaswel/time-converter

最新稳定版本:1.0.0

Composer 安装命令:

composer require dcaswel/time-converter

包简介

A PHP package for converting a unit of time into another unit of time.

README 文档

README

A fluent PHP package for converting one unit of time into another unit of time.

Have you ever wanted an elegant way to get a certain amount of time worth of seconds? Let's say you're using a caching system where you need to set the ttl in a number of seconds. Does this look familiar?

//One day's worth of seconds
$ttl = 24 * 60 * 60;

Have you ever wanted to have something that was easier to read that is self documenting. That's where this package comes in. Here's the equivalent line of code using Time Converter:

use Dcaswel\TimeConverter\TimeConverter;

$ttl = TimeConverter::convert()->oneDay()->toSeconds();

Now, let's take a deeper look...

Installation

composer require dcaswel/time-converter

Usage

This package can be used for converting almost any length of time into any other length of time.

Examples

TimeConverter::convert()->days(5)->toSeconds(); //432000
TimeConverter::convert()->years(2)->toMonths(); //24
TimeConverter::convert()->weeks(20)->toDays(); //140
...

Note: In order to keep the numbers whole, a month is considered 28 days.

You can also combine methods to get a more precise time:

TimeConverter::convert()->weeks(2)->days(5)->toDays(); //19

For any method in the class, you can also call a singular version of it by prepending one to the beginning and removing the s. For example:

  • weeks() can be oneWeek()
  • days() can be oneDay()
  • etc.

API

/**
 * Methods to set the time being converted 
 */
 
public function minutes(int $number)
public function hours(int $number)
public function days(int $number)
public function weeks(int $number)
public function months(int $number)
public function years(int $number)

/**
 * Methods to get the number you want to convert to
 */

public function toSeconds(): int|float
public function toMinutes(): int|float
public function toHours(): int|float
public function toDays(): int|float
public function toWeeks(): int|float
public function toMonths(): int|float
public function toYears(): int|float

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固