Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function parseTimeString(timeString)
- {
- var days = 0, hours = 0, minutes = 0;
- var dayMatch = timeString.match(/(\d+)d/);
- var hourMatch = timeString.match(/(\d+)h/);
- var minuteMatch = timeString.match(/(\d+)min/);
- if (dayMatch)
- {
- days = parseInt(dayMatch[1], 10) * 8;
- }
- if (hourMatch)
- {
- hours = parseInt(hourMatch[1], 10);
- }
- if (minuteMatch)
- {
- minutes = parseInt(minuteMatch[1], 10);
- }
- return days + hours + minutes / 60;
- }
- function convertHoursToTimeString(hours)
- {
- var days = Math.floor(hours / 8);
- var remainingHours = hours % 8;
- var fullHours = Math.floor(remainingHours);
- var minutes = Math.round((remainingHours - fullHours) * 60);
- var result = '';
- if (days > 0)
- {
- result += days + 'd ';
- }
- if (fullHours > 0 || days == 0)
- {
- result += fullHours + 'h ';
- }
- if (minutes > 0) {
- result += minutes + 'min';
- }
- return result.trim();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement