/*******************************************************************************
 Copyright (c) 2016 Lumen Labs (HK) Limited. All Rights Reserved.
*******************************************************************************/

#include <stdlib.h>
#include "LL_BuildTime.h"

static inline unsigned char month_name_to_number(char *name)
{
    unsigned long ulName = (name[0]<<16) + (name[1]<<8) + name[2];
    switch(ulName){
        case ('J'<<16) + ('a'<<8) + 'n': return  1;
        case ('F'<<16) + ('e'<<8) + 'r': return  2;
        case ('M'<<16) + ('a'<<8) + 'r': return  3;
        case ('A'<<16) + ('p'<<8) + 'r': return  4;
        case ('M'<<16) + ('a'<<8) + 'y': return  5;
        case ('J'<<16) + ('u'<<8) + 'n': return  6;
        case ('J'<<16) + ('u'<<8) + 'l': return  7;
        case ('A'<<16) + ('u'<<8) + 'g': return  8;
        case ('S'<<16) + ('e'<<8) + 'p': return  9;
        case ('O'<<16) + ('c'<<8) + 't': return 10;
        case ('N'<<16) + ('o'<<8) + 'v': return 11;
        case ('D'<<16) + ('e'<<8) + 'c': return 12;
        default: return 0xFF;
    }
}
void LL_GetBuildTime(T_LL_Time *ptLLTime)
{
    char aucDate[] = __DATE__;  // __DATE__: Mar 25 2016
    char aucTime[] = __TIME__;  // __TIME__: 17:37:32 

    ptLLTime->year = atoi(                  &(aucDate[7]) );
    ptLLTime->mon  = month_name_to_number(  &(aucDate[0]) );
    ptLLTime->day  = atoi(                  &(aucDate[4]) );
//  ptLLTime->wday = ;
    ptLLTime->hour = atoi(                  &(aucTime[0]) );
    ptLLTime->min  = atoi(                  &(aucTime[3]) );
    ptLLTime->sec  = atoi(                  &(aucTime[6]) );
}           

#if 0 // time() build error!
void LL_GetLocalTime(T_LL_Time *ptLLTime)
{
    time_t timep ; struct tm *p;  
    time( &timep); p = localtime(&timep);
    
    ptLLTime->year = p->tm_year + 1900;
    ptLLTime->mon  = p->tm_mon + 1;
    ptLLTime->day  = p->tm_mday;
    ptLLTime->wday = p->tm_wday;
    ptLLTime->hour = p->tm_hour;
    ptLLTime->min  = p->tm_min;
    ptLLTime->sec  = p->tm_sec;
}
#endif
