#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "com_time.h"
#include "com_func.h"
/*
 * Definition of leap year:

Rule 1: A year is called leap year if it is divisible by 400.
For example: 1600, 2000 etc leap year while 1500, 1700 are not leap year.
Rule 2: If year is not divisible by 400 as well as 100 but it is divisible by 4 then that year are also leap year.
For example:  2004, 2008, 1012 are leap year.
*/
int isleapyear(int year)
{
    if ((year%400 == 0) || ((year%4 == 0) && (year%100 != 0))) {
        printf("The year:%d is a leap year!\n",year);
        return 1;
    }
    return 0;
}

int istimelegal(int year, int month, int day){
    if(year <= 0 || year >=3000)
    {
        printf("the year is out of range([0-3000]!\n");
        exit(EXIT_FAILURE);
    }else {
        if(isleapyear(year))
        {
            if(month < 1 || month >12)
            {
                printf("The month of the leap year is out of range\n!");
            }else {
                if(month == 2)
                {
                    if(day > 29)
                    {
                        printf("day:%d is out of range",day);
                        exit(EXIT_FAILURE);
                    }
                }
                else{
                    if((day <= 0) || (day > 31))
                    {
                        printf("day:%d is out of range",day);
                        exit(EXIT_FAILURE);
                    }
                }

            }
        }else {//not leap year
            if(month == 2)
            {
                if(day > 28)
                {
                    printf("The month:%d of the year is out of range\n!",month);
                    exit(EXIT_FAILURE);
                }
            }else {
                if((day <= 0) || (day > 31))
                {
                    printf("day:%d is out of range",day);
                    exit(EXIT_FAILURE);
                }

            }

        }
    }
    return 1;

}

//2016-05-02
char *nextday(char *date)
{
    int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    char str_year[5]={0};
    char str_month[3]={0};
    char str_day[3]={0};
    int year=0;
    int month=0;
    int day=0;
    //strncpy();
    sscanf(date,"%4s-%2s-%2s",str_year,str_month,str_day);
    /*printlog(str_year);
    printlog(str_month);
    printlog(str_day);
    printf("%s-%s,%s%s,%s,%s\n",str_year,str_month,str_day);*/
    year = atoi(str_year);
    month = atoi(str_month);
    day = atoi(str_day);
    //printf("day:%d-%d-%d\n",year, month, day);
    if(isleapyear(year))
    {
        days[2] = 29;
    }
    else {
        days[2] = 28;
    }

    //judge time illegal or not
    istimelegal(year,month,day);
    int i = 0;
    int tmp = 0;
    tmp = month;
    for(i = 1;i < 13;i++)
    {
        if(tmp != i)
        {
            continue;
        }else {
            if(day < days[i])
            {
                printlog("&&&&&&&&&&");
                day++;
            }else if(day == days[i]){
                printlog("0000000");
                month++;
                if(month > 12)
                {
                    printlog("121212122");
                    year++;
                    month %= 12;
                }
                printlog("********");
                day = 1;

            }else {
                printlog("@@@@@@@@@@");
                break;
            }
            /*printlog("&&&&&&&&&&");
            day++;
            printlog("@@@@@@@@@@");*/
        }
    }

    //printf("day:%d-%d-%d\n",year, month, day);
    sprintf(date, "%4d-%0d-%0d", year, month, day);
    //printlog(date);
    //printf("%s\n",date);

    return date;
}
---------------------------------------------------------------------------------------
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main(int argc, char *argv[])
{
    //char date[]="2016-03-31";
    //char date[]="2016-02-29";
    //char date[]="2016-03-09";
    //char date[]="2016-12-31";

    //char date[]="2015-03-31";
    char date[]="2015-02-29";
    //char date[]="2015-03-09";
    //char date[]="2015-12-31";
    //printf("%d\n",isleapyear(2015));
    
    nextday(date);
    
    printlog(date);
    return 0;
}

NEXTDAY的更多相关文章

  1. nextDay、beforeDay以及根据nextDay(beforeDay)求解几天后的日期,几天前的日期和两个日期之间的天数

    实现代码: package com.corejava.chap02; public class Date { private int year; private int month; private ...

  2. Nextday 参数化单元测试(测试用例)设计

    一.首先简单描述一下下载试题及配置试题的过程 配置环境:安装Eclipse.JDK(1.7).及考试插件 (net.mooctest....*.jar)等: 登录系统:运行Eclipse: [Mooc ...

  3. 软件测试(三)—— 参数化测试用例(Nextday.java)

    import static org.junit.Assert.*; import java.lang.reflect.Array; import java.util.Arrays; import ja ...

  4. 代码的坏味道(22)——不完美的库类(Incomplete Library Class)

    坏味道--不完美的库类(Incomplete Library Class) 特征 当一个类库已经不能满足实际需要时,你就不得不改变这个库(如果这个库是只读的,那就没辙了). 问题原因 许多编程技术都建 ...

  5. [转]SQL 常用函数及示例

    原文地址:http://www.cnblogs.com/canyangfeixue/archive/2013/07/21/3203588.html --SQL 基础-->常用函数 --===== ...

  6. JDK1.5/1.6/1.7之新特性总结(转载)

    原文地址:http://www.cnblogs.com/yezhenhan/archive/2011/08/16/2141510.html 如果原作者看到不想让我转载请私信我! 开发过程中接触到了从j ...

  7. Linux系统1.md

    计算机 介绍 电子计算机(英语:computer),亦称电脑,是一种利用电子学原理,根据一系列指令对数据进行处理的工具. 在现代,机械计算机的应用已经完全被电子计算机所替换,其所相关的技术研究叫计算机 ...

  8. java高新技术-枚举

    1.什么是枚举 枚举是jdk1.5后才增加的新特性 用枚举就是要规定一个新的类型,那么要用这个类型的值就必须是我规定的那些值.如果不是那些值,编译器就会报错,好处是编译时就会做出判断 2.用普通类模拟 ...

  9. C#重构之道

    定义 重构的定义:在不改变软件可观察行为的前提下,改善其内部结构. 其中,不改变软件行为,是重构最基本的要求.要想真正发挥威力,就必须做到“不需了解软件行为”. 如果一段代码能让你容易了解其行为,说明 ...

随机推荐

  1. ecshop 在php5.5上安装错误解决

    1.找到ecshop\includes\cls_image.php文件 搜索 function gd_version 改成 static function gd_version 2.Strict St ...

  2. HTTP协议详解(一直在用可是这篇太好了转一下)

    引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...

  3. Log4j使用教程 log4:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).

    1.Logger类 通过Logger类的静态方法Logger.getRootLogger得到RootLogger.所有其他的loggers是通过静态方法Logger.getLogger来实例化并获取的 ...

  4. iOS-Auto property synthesis will not synthesize property 'delegate'; it will be implemented by its super

    今天在XCode6.3上面重写TabBar的时候,自定义tabBar的代理遇到的一个问题 在重写tabBar的代理的时候遇到了一个警告. 解决方法: 在.m文件中 警告消失.

  5. thinkphp-1

    thinkphp网站: http://thinkphp.cn, http://bbs.thinkphp.cn 在设置文件夹查看试图的时候, 只点" 应用到所有文件夹" 不要点&qu ...

  6. ASP.NET使用FileUpload上传文件

    前台代码: <asp:FileUpload ID="fuKeleyi" runat="server" /> <asp:Button ID=&q ...

  7. 是智能手机推动windows xp系统停止服务吗

    昨天是windows xp系统停止服务的大限,各大媒体争相报道,漫天铺地的xp消息充斥网络,xp这个词的百度指数这段时间从4月1日的8411也开始猛涨,特别是这两天4月7日的36470飙升到4月8日的 ...

  8. 用WP_Query自定义WordPress 主循环

    我们知道操作 WordPress 主循环(WordPress Loop)最容易的方法是使用 query_posts 函数. 但是使用 query_posts 直接修改 WordPress 默认的主循环 ...

  9. 关于seajs

    (这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 最近经常听到各种JS前缀的名称,瞬间感觉自己弱爆了,啥都没用过呢,这么下去将来怎么嫁人呢.   ...

  10. [BZOJ1998][Hnoi2010]Fsk物品调度

    [BZOJ1998][Hnoi2010]Fsk物品调度 试题描述 现在找工作不容易,Lostmonkey费了好大劲才得到fsk公司基层流水线操作员的职位.流水线上有n个位置,从0到n-1依次编号,一开 ...