A sign showing grouped opening hours of a cafe You have probably seen these signs on the doors of various shops:


  OPENING HOURS
  
  mon-fri 0900-1800
  sat-sun 1100-1530


The task here is to generate a sign like that, grouping consecutive days with the same opening hours, from a list of opening hours for the whole week. Note that the week "wraps around" for what is considered consecutive.

Input:


7 elements, representing the opening hours for each day in a week, starting with Monday.
Each element is a string, on the form XXXX-XXXX
Example input:

0900-1800 0900-1800 0930-1730 0930-1730 0900-1500 1100-1500 1100-1500

It's ok to send the input as an array (for instance as input to a function if you don't read from stdin) 


Output:


A list of opening hours, where consecutive days with the same opening hours are shown as a range. Note that sunday (the last day) and monday (the first day) also are consecutive days.
A day where the day doesn't have similar opening hours to the days before or after is printed by itself
Days are specified as three lowercase letters: mon tue wed thu fri sat sun
Remember that first element in the input corresponds to mon, next to tue etc.
Opening hours are shown as in the input
Two examples

mon-fri 0900-1800, sat-sun 1100-1500
mon-wed 1030-1530, thu 100-1800, fri-sun 1200-1630

The output should be sorted, so ranges appear in the order the days do in the week. Monday is preferred to be first, but it may happen it is not first in a group because the week wraps. So in this case tue is the first range.

tue-fri 0900-1800, sat-mon 1100-1500

Don't group unless consecutive, here wednesday and friday have same opening hours but are separated by a Thursday with different opening hours so they are listed by themselves.

mon-tue 1000-1200, wed 0900-1500, thu 1000-1800, fri 0900-1500, sat-sun 1000-1500

The output can be either comma-separated as the examples here, or separated by a newline as in the example on top.


Test cases

First line is input, second line is expected output

0900-1800 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
mon-fri 0900-1800, sat-sun 1100-1500

0900-1800 0900-1800 0900-1800 0930-1700 0900-1800 1100-1500 1100-1500
mon-wed 0900-1800, thu 0930-1700, fri 0900-1800, sat-sun 1100-1500

1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
tue-fri 0900-1800, sat-mon 1100-1500

1100-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
wed-sat 0900-1800, sun-tue 1100-1500

1200-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
mon 1200-1500, tue 1100-1500, wed-sat 0900-1800, sun 1100-1500


Rules

This is code-golf, so the shortest answer in bytes wins.
JavaScript (ES6), 182 173 170 163 157 bytes

Saved 6 bytes with the help of edc65

Takes input as an array of strings and directly prints the result to the console:

h=&gt;{for(D="montuewedthufrisatsun".match(/.../g),d=c=i=j=0;j&lt;8;y=d)h[i]==h[6]?i++:(v=h[d=(i+j++)%7])!=c&amp;&amp;(j&gt;1&amp;&amp;console.log(D[x]+(x-y?'-'+D[y]:''),c),x=d,c=v)}


Formatted and commented

h =&gt; {                               // input = list h of opening hours
  for(                               //
    D = "montuewedthufrisatsun"      // D = list of abbreviated names of days
        .match(/.../g),              //
    d =                              // d = current day of week
    c =                              // c = current opening hours
    i =                              // i = first day of week to process
    j = 0;                           // j = day counter
    j &lt; 8;                           // stop when 7 days have been processed
    y = d                            // update y = last day of current day range
  )                                  //
  h[i] == h[6] ?                     // while the opening hours of day #i equal the opening
    i++                              // hours of sunday: increment i
  : (v = h[d = (i + j++) % 7]) != c  // else, if the new opening hours (v) of the current
    &amp;&amp; (                             // day (d) doesn't match the current opening hours (c):
      j &gt; 1 &amp;&amp;                       //   if this is not the first iteration:
        console.log(                 //     print:
          D[x] +                     //     - the first day of the current day range (x)
          (x - y ?                   //     - followed by either an empty string
            '-' + D[y]               //       or a '-' and the last day of the range
          : ''),                     //       (if they differ)
          c                          //     - the corresponding opening hours
        ),                           //   (endif)
      x = d,                         //   update x = first day of current day range
      c = v                          //   update c = current opening hours
    )                                // (endif)
}                                    // (end)


Test cases



let f =

h=&gt;{for(D="montuewedthufrisatsun".match(/.../g),d=c=i=j=0;j&lt;8;y=d)h[i]==h[6]?i++:(v=h[d=(i+j++)%7])!=c&amp;&amp;(j&gt;1&amp;&amp;console.log(D[x]+(x-y?'-'+D[y]:''),c),x=d,c=v)}

f(["0900-1800", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["0900-1800", "0900-1800", "0900-1800", "0930-1700", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["1100-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500"]);
console.log('-');
f(["1200-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500"]);