PHPackages                             lsv/timestringparser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lsv/timestringparser

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lsv/timestringparser
====================

Parse a text string to minutes in integer

v2.0.1(9y ago)3162MITPHPPHP ^7.0

Since May 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/lsv/timestringparser)[ Packagist](https://packagist.org/packages/lsv/timestringparser)[ RSS](/packages/lsv-timestringparser/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (7)Versions (4)Used By (0)

Time string parser ● [![Build Status](https://camo.githubusercontent.com/48cea49ebc0995b026ea9754c47e2738973fc9530a3abe1a9b647d6987c1fd81/68747470733a2f2f7472617669732d63692e6f72672f6c73762f74696d65737472696e677061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lsv/timestringparser) [![Coverage Status](https://camo.githubusercontent.com/b144df14df4b9743133fc6b4b3c44bb8d679cee3af90eef9fa38eaa5cd22d6eb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c73762f74696d65737472696e677061727365722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/lsv/timestringparser?branch=master)
=======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#time-string-parser---)

If you have strings like 1h30m and want this to be a integer with minutes, this is for you.

The hour letters and minute letters can be customized and also multiple is allowed.

- 1h20m = 80
- 3:24 = 204
- 954 = 954

And if you have multiple hour letters you can set these in the constructor, see under [usage](#Usage), so you can end up with parsing multiple letters

- 2t20 = 140
- 3x84s = 264

##### New in 2.0

[](#new-in-20)

- You can now add a low minute, meaning if set it to 4, then if you write 3, it will become 3 hours, if you write 5 it will still be 5 minutes.
- By default the `low minute` variable is NULL, meaning its not used

### Install

[](#install)

`composer require lsv/timestringparser`

or add

```
{
    "require": {
        "lsv/timestringparser": "^1.0"
    }
}
```

to your `composer.json`

### Usage

[](#usage)

By standard hour letter is `h` and minute letter is `m` but these can be customized in the constructor `new TimestringParser(['h','t','u'], ['m','x','y']);` now `h`, `t` and `u` can be used to parse the hour part of the time string, and the letters `m`, `x`, `y` can be used to parse the minute part of the time string

##### New in 2.0

[](#new-in-20-1)

You can set the `low minute` variable in the constructor `new TimestringParser(['h','t','u'], ['m','x','y'], );`

It needs to be a integer

### Examples

[](#examples)

```
$timestrings = [
    '3:20', '1h 42m', '1u 22x', '3u55x',
    20, '1h', '48h84y', '3t994x'
];
$parser = new TimestringParser(['h','t','u'], ['m','x','y']);
foreach($timestrings as $string) {
    echo $parser->parseTimeString($string); // Return integers
}
```

##### Low minute example

[](#low-minute-example)

```
$timestrings = [1, 2, '3', '4', 5];
$parser = new TimestringParser(['h'], ['m'], 3);
echo $parser->parseTimeString(1); // Returns 60
echo $parser->parseTimeString(2); // Returns 120
echo $parser->parseTimeString('3'); // Returns 180
echo $parser->parseTimeString('4'); // Returns 4
echo $parser->parseTimeString(5); // Returns 5

```

### License

[](#license)

The MIT License (MIT)

Copyright (c) 2016 Martin Aarhof

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~158 days

Total

3

Last Release

3373d ago

Major Versions

v1.0 → v2.02017-04-05

PHP version history (2 changes)v1.0PHP ^5.5.9

v2.0PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff9304e6a7caa208d631a1529240a97dff2f47dadde7bff153e8a90818047168?d=identicon)[lsv](/maintainers/lsv)

---

Top Contributors

[![lsv](https://avatars.githubusercontent.com/u/20708?v=4)](https://github.com/lsv "lsv (7 commits)")[![tomschlick](https://avatars.githubusercontent.com/u/70184?v=4)](https://github.com/tomschlick "tomschlick (1 commits)")

---

Tags

textparseMinutes

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/lsv-timestringparser/health.svg)

```
[![Health](https://phpackages.com/badges/lsv-timestringparser/health.svg)](https://phpackages.com/packages/lsv-timestringparser)
```

###  Alternatives

[ckeditor/ckeditor

JavaScript WYSIWYG web text editor.

5454.3M79](/packages/ckeditor-ckeditor)[enqueue/dsn

Parse DSN

12526.3M57](/packages/enqueue-dsn)[tinymce/tinymce

Web based JavaScript HTML WYSIWYG editor control.

1707.9M118](/packages/tinymce-tinymce)[gabrielelana/byte-units

Library to parse, format and convert byte units

1682.3M20](/packages/gabrielelana-byte-units)[mtownsend/read-time

A PHP package to show users how long it takes to read content.

282616.7k2](/packages/mtownsend-read-time)[nojimage/twitter-text-php

A library of PHP classes that provide auto-linking and extraction of usernames, lists, hashtags and URLs from tweets.

1191.9M7](/packages/nojimage-twitter-text-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
