└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # bizhours.js 2 | 3 | bizhours.js is a lightweight javascript library for parsing storing, displaying and querying 4 | a business' open hours. It's developed and maintained at Zendesk for the link-sf.org project. 5 | 6 | ## howto use 7 | 8 | > var h = new BizHours({sun: "9am-7pm", mon: "10am-7pm", wed: "4am-5am", thu: "4am-5am"}) 9 | > h.humanize().forEach(function(day) { 10 | console.log(day.day); 11 | console.log(day.hours) 12 | }); 13 | 14 | Sunday 15 | 9am - 7pm 16 | Monday 17 | 10am - 7pm 18 | Tuesday 19 | null 20 | Wednesday 21 | 4am - 5am 22 | Thursday 23 | 4am - 5am 24 | Friday 25 | null 26 | Saturday 27 | null 28 | 29 | > h.humanizeCondensed().forEach(function(range) { 30 | console.log(range.day); 31 | console.log(range.hours) 32 | }); 33 | 34 | Sunday 35 | 9am - 7pm 36 | Monday 37 | 10am - 7pm 38 | Wednesday - Thursday 39 | 4am - 5am 40 | 41 | ## more: 42 | 43 |

44 | constructor 45 | new BizHours(hoursObject) 46 |
47 | Creates a new BizHours object from hoursObject input. hoursObject is a javascript obj with keys of ["mon", "tue", "wed", "thu", "fri", "sat", "sun"], and values 48 | of the following format: "9am-1pm, 1:30pm - 5:30pm". 49 | var h = new BizHours({mon: "9am - 1pm", tue: "11am - 3pm"}) 50 |

51 | addDay 52 | .addDay(dayName, timeString) 53 |
54 | Sets dayName's open hours to the parsed value of timeString. The format of dayName and timeString follow the constructor's arguments. 55 | 56 | h.addDay("mon", "5pm-7pm") 57 | 58 |

59 | merge 60 | .merge(hoursObject) 61 |
62 | Merge hoursObject (a bizHours object) into this object. 63 | 64 | h.merge(other) 65 | 66 |

67 | humanize 68 | .humanize() 69 |
70 | Return an array objects representing open hours 71 | 72 | > h.humanize() 73 | [ 74 | {day: "Monday", 75 | hours: "9am-5pm"}, 76 | {day: "Tuesday", 77 | hours: "9am-5pm"}, 78 | ... 79 | ] 80 | 81 |

82 | humanizeCondensed 83 | .humanizeCondensed() 84 |
85 | The same as .humanize, but with runs of days that have the same hours collapsed into one array entry: 86 | 87 | > h.humanizeCondensed() 88 | [ 89 | {day: "Monday - Tuesday", 90 | hours: "9am-5pm"}, 91 | {day: "Wednesday", 92 | hours: "11am-5pm"}, 93 | ... 94 | ] 95 |

96 | within 97 | .within(date) 98 |
99 | Returns whether the given date is within the business' open hours (assuming that the date and biz hours are within the same timezone). 100 | 101 | 102 | 103 | 104 | --------------------------------------------------------------------------------