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#重构之道
定义 重构的定义:在不改变软件可观察行为的前提下,改善其内部结构. 其中,不改变软件行为,是重构最基本的要求.要想真正发挥威力,就必须做到“不需了解软件行为”. 如果一段代码能让你容易了解其行为,说明 ...
随机推荐
- java return
return语句的作用: 1.返回一个值,可以是任意类型的 2.使程序返回到操作系统,或者说是代表"已经做完,离开此方法" ---------------------------- ...
- MongoDB过过瘾
MongoDB 中默认的数据库为 test,连接后尝试以下操作 连接 插入数据:用过json的同学看到这格式相信不会陌生吧! db.person.insert({}) db.person.insert ...
- 【bzoj1023】仙人掌图
[bzoj1023]仙人掌图 题意 给一棵仙人掌,求直径. \(n\leq 100000\) 分析 分析1:[Tarjan]+[环处理+单调队列优化线性dp]+[树形dp] 分开两种情况处理: ①环: ...
- SDK ";iphoneos"; cannot be located
在MAC下,交叉编译libvlc出现的一些问题和解决方法.项目中使用了libvlc开源库.在执行编译脚本中,遇到一句xcrun --sdk iphoneos --show-sdk-path报错 mac ...
- windows应用中调用DLL一步步试验
试验环境: PC:win10 build 10143 IDE: vs2015 RC WinPhone: win10 build 10136 简单界面,点按钮,算加法 一.主程用C++ 1.新建visu ...
- node &; grunt path处理相关
在nodejs平台上写一些工具或者服务, 有很多需求会涉及到对目录或者文件路径的处理和操作.整理一些常用的处理path的方法 1.global __dirname Example: running n ...
- Nginx负载-nginx转发到Swoole服务器(nginx配置文件变更)
- python 安装influxdb-python
一.Linux下安装 1.yum install -y git 2.安装pip,参考:https://app.yinxiang.com/shard/s41/sh/0338ba85-5443-453f- ...
- Kafka 0.8 NIO通信机制
一.Kafka通信机制的整体结构 同时,这也是SEDA多线程模型. 对于broker来说,客户端连接数量有限,不会频繁新建大量连接.因此一个Acceptor thread线程处理新建连接绰绰有余. K ...
- java 泛型详解-绝对是对泛型方法讲解
Reference: http://blog.csdn.net/s10461/article/details/53941091 1. 概述 泛型在java中有很重要的地位,在面向对象编程及各种设计模 ...