savannah-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Savannah-hackers] submission of DateTime to UTC - savannah.gnu.org


From: sankaran nambi
Subject: Re: [Savannah-hackers] submission of DateTime to UTC - savannah.gnu.org
Date: Mon, 10 Nov 2003 22:58:07 -0800 (PST)

Hi Rudy,
 
I have registered the project again.
Also the source code is attached with the source file.
I am not sure the disclaimer is right, but I took it out of the site.
When I make the project complete I can create a COPYING file.
Please review and Let me know.
 
Thanks,
Nambi

Rudy Gevaert <address@hidden> wrote:
Please register your project again and include an (temporary) URL
pointing to the source code. The description you gave when
registering will not be read by the general public. If you are still
concerned with privacy, however, you can forward the code to me by
email.

We wish to review your source code, even if it is not functional, to
catch potential legal issues early.

For example, to release your program properly under the GPL you must
include a copyright notice and permission-to-copy statements at the
beginning of every file of source code. This is explained in
http://www.gnu.org/licenses/gpl-howto.html. Our review would help
catch potential omissions such as these.


--
Rudy Gevaert address@hidden
Web page http://www.webworm.org
GNU/Linux for schools http://www.nongnu.org/glms
Savannah hacker http://savannah.gnu.org


408.480.0039 [c]


Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
/*  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  This file is part of Time To UTC.
 *
 *  Time To UTC is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Time To UTC is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
 *  along with Time To UTC; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*********************************************************************************
 *
 * Name    : time2utc.c
 * Purpose : building a standalone utility for converting
 *           time to UTC
 * Author  : Nambi Sankaran
 * Version : 1.0, Sun Dec 16 2001, Cupertino
 * Changes :
 *
 
********************************************************************************/
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>

#define DATELEN 9
#define TIMELEN 9
#define FORMATLEN 256
#define YEARLEN 5
extern int errno;

int usage();
int main(int argc, char **argv)
{
        int c;
        char date[DATELEN],time[TIMELEN], year_str[YEARLEN]; 
        char format[FORMATLEN], string[FORMATLEN];
        char zone[TIMELEN];
        char zone_env[TIMELEN+10];
        int mon, day, year;
        char month[10];
        char dayofmonth[10];
        time_t utc_time;
        
        int hour, minute, second;
        char hr[3], min[3], sec[3];

        extern char *tzname[2];
        extern time_t timezone, altzone;
        extern int daylight;

        struct tm time_var;

        strcpy(zone,"null");
        strcpy(time,"null");
        strcpy(date,"null");
        
        if( argc == 1 )
                return usage();

        /* Eventually Add the Fortmat of Input Date/Time
           The program should be able to handle it by constructing
           the right format string for strptime.
           Atpresent It Supports only one format */

        while((c = getopt(argc, argv, "d:t:z:")) != EOF )
        {
                switch((char)c)
                {
                        case 'd':
                                strncpy(date,optarg,DATELEN);
                                break;
                        case 't':
                                strncpy(time,optarg,TIMELEN);
                                break;
                        case 'z':
                                strcpy(zone,optarg);
                                break;
                        case '?':
                                return usage();
                        default:
                                break;
                }
        }

        /* If the date is given                 */
        /* Get the Month Name from Month Number */

        if( strcmp(date,"null") != 0 ){ 
        strncpy(month,date,2);
        mon = atoi(month);
        
        if( mon > 0 && mon <= 12 )
        {
                if( mon == 1 )
                        strcpy(month,"Jan");
                if( mon == 2 )
                        strcpy(month,"Feb");
                if( mon == 3 )
                        strcpy(month,"Mar");
                if( mon == 4 )
                        strcpy(month,"Apr");
                if( mon == 5 )
                        strcpy(month,"May");
                if( mon == 6 )
                        strcpy(month,"Jun");
                if( mon == 7 )
                        strcpy(month,"Jul");
                if( mon == 8 )
                        strcpy(month,"Aug");
                if( mon == 9 )
                        strcpy(month,"Sep");
                if( mon == 10)
                        strcpy(month,"Oct");
                if( mon == 11)
                        strcpy(month,"Nov");
                if( mon == 12)
                        strcpy(month,"Dec");
        }
        else{
                printf("The value for month is wrong\n");
                printf("It should have a value from 1-12\n");
                exit(-1);
        }

        /* Get the Date */
        strncpy(dayofmonth,date+2,2);
        day = atoi(dayofmonth);

        if((mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12) && day > 
31 )
        {
        printf("The value for day is wrong\n");
        printf("It should have a value from 1-31\n");
        printf("For the months of January, March, May, July, August, October 
and December\n");
        exit(-1);
        }
        else if((mon==2||mon==4||mon==6||mon==9||mon==11) && day > 30 )
        {
        printf("\tThe value for day is wrong, ");
        printf("it should have a value from 1-30\n");
        printf("\tfor the months of February, April, June, September and 
November\n");
        printf("\tHowever, If a day of Feb 30 is specified, it will be 
converted into a\n");
        printf("\tLegal UTC value corresponding to March 2\n");
        printf("\tSo care should be taken to when specifying days in 
February\n");
        printf("\teventhough no harm is done\n\n"); 
        usage();
        exit(-1);
        }


        /* Get The Year */
        strncpy(year_str,date+4,YEARLEN-1);
        year = atoi(year_str);

        }

        /* If the time is given, then */
        /* Get the Hour, Minute and second */

        if( strcmp(time,"null") != 0 ){
        strncpy(hr,time,2);
        strncpy(min,time+3,2);
        strncpy(sec,time+6,2);

        hour = atoi(hr);
        minute = atoi(min);
        second = atoi(sec);

#ifdef VERBOSE
        printf("%s %s %s\n", hr, min, sec);
#endif

        if( hour < 0 || hour >= 24)
        {
                printf("\nThe value for hour is wrong, ");
                printf("it should have a value from 0-23\n");
                usage();
                exit(-1);
        }
        
        if( minute < 0 || minute >= 60)
        {
                printf("\tThe value for minute is wrong, ");
                printf("it should have a value from 0-59\n\n");
                usage();
                exit(-1);
        }

        if( second < 0 || second >= 62)
        {
                printf("\tThe value for minute is wrong, ");
                printf("it should have a value from 0-59\n");
                printf("\tSeconds may have values upto 61 to adjust\n");
                printf("\tfor occasional leap second and even more occasional 
double leap second\n\n");
                usage();
                exit(-1);
        }

        }

#ifdef VERBOSE
        printf("%s %d %d \n", month, day, year);
        printf("timezone = %s\n", getenv("TZ"));
        printf("Timezone =%p\n", *tzname[0]);
#endif
        
        /* construct the format string, for input to strptime */

        if( strcmp(zone,"null") != 0 )
        {
        strcpy(format,"%b%n%d%n%Y%n%H%n%M%n%S"); 
        sprintf(string,"%s %2d %2d %2d %2d %2d",month,day, year, 
hour,minute,second);
        sprintf(zone_env,"TZ=%s", zone);
        putenv(zone_env);
        tzset();
        }else{
        strcpy(format,"%b%n%d%n%Y%n%H%n%M%n%S"); 
        sprintf(string,"%s %2d %2d %2d %2d %2d",month,day, year, 
hour,minute,second);
        }

#ifdef VERBOSE
        printf("Format = %s String %s len = %d\n", format, string, 
strlen(string));
        printf("Timezone = %s\n", getenv("TZ"));
        printf("Timezone =%s\n", *tzname[0]);
#endif

        if( strptime(string, format, &time_var) == NULL )
        {
                printf("\nWrong date  or format %d \n", errno);
                usage();
                exit(-1);
        }

        utc_time = mktime( &time_var);

#ifdef VERBOSE
        printf("\nhr %d min %d sec %d\n", time_var.tm_hour, time_var.tm_min, 
time_var.tm_sec);
        printf("mon %d day %d year %d\n",time_var.tm_mon, time_var.tm_mday, 
time_var.tm_year);
        printf("day of week %d day of year %d is_delayed 
%d\n",time_var.tm_wday, time_var.tm_yday, time_var.tm_isdst);
#endif
        printf("%ld\n",utc_time);
}

int usage()
{
        printf("Usage : time2utc -d MMDDCCYY -t HH24:MM:SS -z [TIME_ZONE] \n");
        printf("        By Default TIME_ZONE is to the default system 
time-zone\n");
        printf("        However it supports Both the standard & delayed 
notations\n");
        printf("        In future this program will support Different Formats 
of Date/Time\n");
        return -1;

}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]