NEXTDAY
#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的更多相关文章
- nextDay、beforeDay以及根据nextDay(beforeDay)求解几天后的日期,几天前的日期和两个日期之间的天数
实现代码: package com.corejava.chap02; public class Date { private int year; private int month; private ...
- Nextday 参数化单元测试(测试用例)设计
一.首先简单描述一下下载试题及配置试题的过程 配置环境:安装Eclipse.JDK(1.7).及考试插件 (net.mooctest....*.jar)等: 登录系统:运行Eclipse: [Mooc ...
- 软件测试(三)—— 参数化测试用例(Nextday.java)
import static org.junit.Assert.*; import java.lang.reflect.Array; import java.util.Arrays; import ja ...
- 代码的坏味道(22)——不完美的库类(Incomplete Library Class)
坏味道--不完美的库类(Incomplete Library Class) 特征 当一个类库已经不能满足实际需要时,你就不得不改变这个库(如果这个库是只读的,那就没辙了). 问题原因 许多编程技术都建 ...
- [转]SQL 常用函数及示例
原文地址:http://www.cnblogs.com/canyangfeixue/archive/2013/07/21/3203588.html --SQL 基础-->常用函数 --===== ...
- JDK1.5/1.6/1.7之新特性总结(转载)
原文地址:http://www.cnblogs.com/yezhenhan/archive/2011/08/16/2141510.html 如果原作者看到不想让我转载请私信我! 开发过程中接触到了从j ...
- Linux系统1.md
计算机 介绍 电子计算机(英语:computer),亦称电脑,是一种利用电子学原理,根据一系列指令对数据进行处理的工具. 在现代,机械计算机的应用已经完全被电子计算机所替换,其所相关的技术研究叫计算机 ...
- java高新技术-枚举
1.什么是枚举 枚举是jdk1.5后才增加的新特性 用枚举就是要规定一个新的类型,那么要用这个类型的值就必须是我规定的那些值.如果不是那些值,编译器就会报错,好处是编译时就会做出判断 2.用普通类模拟 ...
- C#重构之道
定义 重构的定义:在不改变软件可观察行为的前提下,改善其内部结构. 其中,不改变软件行为,是重构最基本的要求.要想真正发挥威力,就必须做到“不需了解软件行为”. 如果一段代码能让你容易了解其行为,说明 ...
随机推荐
- gotoTop返回顶部 JS
方法: 1.首先在body添加一个标签,在一个页面添加,其它页面也会生效. <body> <a name="top"> 2.然后在页脚添加一个链接 < ...
- Codeforces 548B Mike and Fun
传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- form的submit与onsubmit的用法与区别
发生顺序:onsubmit -> submit1.阻止表单提单:<script>function submitFun(){ //逻辑判断 return true; //允 ...
- mysql 插入中文时出现ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern ame' at row 1
1 环境: MySQL Server 6.0 命令行工具 2 问题 : 插入中文字符数据出现如下错误: ERROR 1366 (HY000): Incorrect string value: '\ ...
- python urllib2使用心得
python urllib2使用心得 1.http GET请求 过程:获取返回结果,关闭连接,打印结果 f = urllib2.urlopen(req, timeout=10) the_page = ...
- 多线程下载的原理&断点下载的原理
1)多线程下载说明:
- Spring学习2—Spring容器
一.Spring容器接口关系 容器是Spring框架的核心,Spring容器就是一个巨大的工厂.Spring容器使用Ioc(控制反转(Inversion of Control )管理所有组成应用系统的 ...
- [LeetCode] Copy List with Random Pointe
题目的关键是要让新链表和原有链表发送关联,可以通过这种关联来设置新链表的random pointer 思路:将新链表的元素插入到原有链表元素的后面,如下图所示,就可以根据原有链表的radom-> ...
- 在命令行中运行eclipse中创建的java项目
在命令行中运行eclipse中创建的java项目 博客分类: java相关 javaeclipse命令行 由于项目要求,需要对eclipse中的项目进行打包,似的可以在客户机上不装eclipse的情 ...
- 新浪微博客户端(24)-计算原创微博配图frame
DJStatus.h #import <Foundation/Foundation.h> @class DJUser; /** 微博 */ @interface DJStatus : NS ...