Most elegant way to morph this sequence

Posted by Ed Woodcock on Stack Overflow See other posts from Stack Overflow or by Ed Woodcock
Published on 2010-04-14T13:29:41Z Indexed on 2010/04/14 13:33 UTC
Read the original article Hit count: 288

Filed under:
|

Hi folks:

I've got the Day of the week stored in a database table (that I do not control), and I need to use it in my code.

Problem is, I want to use the System.DayOfWeek enum for representation for this, and the sequences are not the same.

In the database, it's as follows:

1  2  3  4  5  6  7
S  M  T  W  T  F  S

I need it as follows:

0  1  2  3  4  5  6
M  T  W  T  F  S  S

What's the most elegant way to do this?

for example, I could do:

i = dayOfWeek;
i = i - 2;
if (i < 0) {
    i = 6;
}

but that's a bit inelegant. Any suggestions?

© Stack Overflow or respective owner

Related posts about sequence

Related posts about enums