//
//  OmUtils.m
//  OmLoc
//
//  Created by david van brink on 7/28/10.
//  Copyright 2010 omino.com. All rights reserved.
//

#import "OmUtils.h"



/*
// temp -- remove loose files from top dir...
{
    NSString *path = [NSString stringWithFormat:@"%@/Documents",NSHomeDirectory()];
    NSArray *items = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
    for(int i = 0; i < [items count]; i++)
    {
        NSString *f = [NSString stringWithFormat:@"%@/%@",path,[items objectAtIndex:i]];
        char lastChar = [f characterAtIndex:[f length]-1];
        if(lastChar == 'g' || lastChar == 'l')
            [[NSFileManager defaultManager] removeItemAtPath:f error:nil];
    }
}
 */


char *nowString()
{
    static char now[100];
    NSDate *date = [NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc]                      initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSDateComponents *components =[gregorian components:NSWeekdayCalendarUnit|NSHourCalendarUnit fromDate:date];
    
    int weekday = [components weekday]; // weekday 1 = Sunday for Gregorian calendar
    int hour = [components hour];
    char *weekdayString;
    char *todString;
    switch(weekday)
    {
        case 0:
        case 7: weekdayString = "Saturday"; break;
        case 1: weekdayString = "Sunday"; break;
        case 2: weekdayString = "Monday"; break;
        case 3: weekdayString = "Tuesday"; break;
        case 4: weekdayString = "Wednesday"; break;
        case 5: weekdayString = "Thursday"; break;
        case 6: weekdayString = "Friday"; break;
        default: weekdayString = "Noday"; break;
    }
    if(hour < 6)       todString = "AM";
    else if(hour < 12) todString = "morning";
    else if(hour < 16) todString = "afternoon";
    else if(hour < 20) todString = "evening";
    else               todString = "night";
    
    sprintf(now,"%s %s",weekdayString,todString);
    
    [gregorian release];
    return now;
    
}