#include <stdio.h>
#include <time.h>
#include <unistd.h>

#ifdef WIN32
struct tm *localtime_nanoo(time_t *_clock, struct tm *_result)
{
    struct tm *p = localtime(_clock);
    if (p)
        *(_result) = *p;
    return p;
}
#endif

main()
{
    time_t now;
    struct tm now_tm;
    unsigned char level[17], x;

    while (2==2) {
#ifdef WIN32
        system("cls");
#else
        system("clear");
#endif
        time(&now);
#ifdef WIN32
        localtime_nanoo(&now, &now_tm);
#else
        localtime_r(&now, &now_tm);
#endif
        float interval=43200, totaltime=0, timenow = now_tm.tm_sec + 60*now_tm.tm_min + 3600*now_tm.tm_hour;

        for (x=0; x<17; x++) {
            if ((timenow >= totaltime) && (timenow < (totaltime + interval))) {
                level[x] = 0;
            } else {
                level[x] = 1;
                totaltime += interval;
            }
            interval /= 2;
        }

        if (level[0] == 0) {
            printf("off ");
        } else {
            printf("on ");
        }

        if (level[1] == 0) {
            printf("early ");
        } else {
            printf("late ");
        }

        if (level[2] == 0) {
            printf("sub ");
        } else {
            printf("super ");
        }

        for (x=3; x<17; x++) {
            printf("%d", level[x]);
        }
        printf("\n");
#ifdef WIN32
        sleep(1000);
#else
        sleep(1);
#endif

    }
    return 0;
} 
