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#重构之道
定义 重构的定义:在不改变软件可观察行为的前提下,改善其内部结构. 其中,不改变软件行为,是重构最基本的要求.要想真正发挥威力,就必须做到“不需了解软件行为”. 如果一段代码能让你容易了解其行为,说明 ...
随机推荐
- jsp学习(二)
jsp运行原理 当服务器上的一个jsp页面被第一次请求标记时,服务器上的jsp引擎首先将jsp页面文件转译成一个Java文件,并编译这个java文件生成字节码文件,然后执行字节码文件响应客户的请求. ...
- POJ1328Radar Installation(区间点覆盖问题)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68597 Accepted: 15 ...
- php中mysql参数化查询
$query = sprintf("SELECT * FROM Users where UserName='%s' and Password='%s'",mysql_real_es ...
- Android打电话&发短信
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView ...
- H2Database数据类型
数据类型 整数(INT) 布尔型(BOOLEAN) 微整数(TINYINT) 小整数(SMALLINT) 大整数(BIGINT) 标识符(IDENTITY) 货币数(DECIMAL) 双精度实数( ...
- prototype.js $F()函数介绍
$F()是一个能够简化编码量的函数, 对于字段输入控件有效,包括input.textarea.select等,该函数的输入参数为这些输入控件元素对象的id或元素对象本身,函数负责返回 这些输入控件元素 ...
- [Socket网络编程]一个封锁操作被对 WSACancelBlockingCall 的调用中断。
原文地址:http://www.cnblogs.com/xiwang/archive/2012/10/25/2740114.html记录在此,方便查阅. C#中在使用UDPClient循环监听端口,在 ...
- metinfo首页内容简介
http://www.hlbaozhuangji.cn/manage/content/other_info.php?anyid=31&lang=cn 首页内容简介: select * from ...
- sql拷贝表结构不拷贝表数据
- 支付宝微信O2O大战,WiFi广告在夹缝中求生存
支付宝微信O2O大战,WiFi广告在夹缝中求生存 来自工信部的数据显示,截至2013年底,中国智能手机的保有量已经达到5.8亿台.国内平均有46%的时间选择WiFi上网. 商用WiFi已经成为了移动互 ...