diff --git a/README.md b/README.md index 8f34155..0baeff2 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ timestring.js attempts to parse a human readable time string into a time based v ```js var str = '1h 15m'; -var time = str.parseTime(); +var time = str.parseTime(); console.log(time); // will log 4500 ``` -In the example above `str` is just a plain old `String` object. timestring.js adds a new method to the `String` objects prototype named `parseTime`. This method parses the string and returns a time based value. +In the example above `str` is just a plain old `String` object. timestring.js adds a new method to the `String` objects prototype named `parseTime`. This method parses the string and returns a time based value. **By default the returned time value will be in seconds.** @@ -19,7 +19,7 @@ The time string can contain as many time groups as needed: ```js var str = '1d 3h 25m 18s'; -var time = str.parseTime(); +var time = str.parseTime(); console.log(time); // will log 98718 ``` @@ -28,7 +28,7 @@ and can be as messy as you like: ```js var str = '1 d 3h 25 m 1 8s'; -var time = str.parseTime(); +var time = str.parseTime(); console.log(time); // will log 98718 ``` @@ -78,14 +78,14 @@ By default the return time value will be in seconds. This can be changed by pass ```js var str = '22h 16m'; -var hours = str.parseTime('h'); // 22.266666666666666 -var days = str.parseTime('d'); // 0.9277777777777778 +var hours = str.parseTime('h'); // 22.266666666666666 +var days = str.parseTime('d'); // 0.9277777777777778 var weeks = str.parseTime('w'); // 0.13253968253968254 // or -var hours = (new Timestring()).parse(str, 'h'); // 22.266666666666666 -var days = (new Timestring()).parse(str, 'd'); // 0.9277777777777778 +var hours = (new Timestring()).parse(str, 'h'); // 22.266666666666666 +var days = (new Timestring()).parse(str, 'd'); // 0.9277777777777778 var weeks = (new Timestring()).parse(str, 'w'); // 0.13253968253968254 ``` @@ -116,17 +116,17 @@ var settings = { var time = str.parseTime('h', settings); -// or +// or var time = (new Timestring(settings)).parse(str, 'h'); -console.log(time) // will log 1 +console.log(time); // will log 1 ``` In the example of above `hoursPerDay` is being set to `1`. When the time string is being parsed, the return value is being specified as hours. Normally `1d` would parse to `24` hours (as by deafult there are 24 hours in a day) but because `hoursPerDay` has been set to `1`, `1d` will now only parse to `1` hour. -This would be useful for specific application needs. +This would be useful for specific application needs. *Example - Employees of my company work 7.5 hours a day, and only work 5 days a week. In my time tracking app, when they type `1d` i want 7.5 hours to be tracked. When they type `1w` i want 5 days to be tracked etc.* @@ -138,18 +138,18 @@ var settings = { // get time values from form input var today = document.querySelector('time-input').value, // '1d' - thisWeek = document.querySelector('time-input').value // '1w'; + thisWeek = document.querySelector('time-input').value; // '1w' // parse times var hoursToday = today.parseTime('h', settings), daysThisWeek = thisWeek.parseTime('d', settings); -// or +// or var hoursToday = (new Timestring(settings)).parse(today, 'h'), - daysThisWeek = (new Timestring(settings)).parse(thisWeek, 'd') + daysThisWeek = (new Timestring(settings)).parse(thisWeek, 'd'); -console.log(hoursToday) // will log 7.5 -console.log(daysThisWeek) // will log 5 -``` \ No newline at end of file +console.log(hoursToday); // will log 7.5 +console.log(daysThisWeek); // will log 5 +```