2017 © Pedro Peláez
 

library timestringparser

Parse a text string to minutes in integer

image

lsv/timestringparser

Parse a text string to minutes in integer

  • Wednesday, April 5, 2017
  • by lsv
  • Repository
  • 1 Watchers
  • 2 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Time string parser ● Build Status Coverage Status

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

The hour letters and minute letters can be customized and also multiple is allowed., (*2)

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

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

  • 2t20 = 140
  • 3x84s = 264
New in 2.0
  • 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

composer require lsv/timestringparser, (*4)

or add, (*5)

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

to your composer.json, (*6)

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, (*7)

New in 2.0

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

It needs to be a integer, (*9)

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
$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

The MIT License (MIT), (*10)

Copyright (c) 2016 Martin Aarhof martin.aarhof@gmail.com, (*11)

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:, (*12)

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

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., (*14)

The Versions

05/04 2017

dev-master

9999999-dev

Parse a text string to minutes in integer

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

text parse minutes

05/04 2017

v2.0.1

2.0.1.0

Parse a text string to minutes in integer

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

text parse minutes

05/04 2017

v2.0

2.0.0.0

Parse a text string to minutes in integer

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

text parse minutes

24/05 2016

v1.0

1.0.0.0

Parse a text string to minutes in integer

  Sources   Download

MIT

The Requires

  • php ^5.5.9

 

The Development Requires

text parse minutes