Check parsing date within date range

So, I'm using a scripting language with syntax like C ++, and I'm trying to find a better way to check if a date is within a range. The problem I am facing is that if the current day is in the new month, the check is not performed.

This is what my code looks like:

if(iMonth >= iStartMonth && iMonth <= iEndMonth)
{
    if(iDay >= iStartDay && iDay <= iEndDay)
    {
        if(iYear >= iStartYear && iYear <= iEndYear)
        {
                bEnabled = true;
                return;

When I have something like this:

    Start date: 3 27 2010
    End Date: 4 15 2010
    Current Date: 3 31 2010

, (iDay <= iEndDay) . , , , "03: 27: 2010" "04: 15: 2010" . , .

+3
5

boost:: DateTime , (, /, , ). , ++, ( ). Lua?:)


:

if(iDay >= iStartDay && iDay <= iEndDay)

, iMonth == iStartMonth, . iDay = 31, iEndDay = 15 31 <= 15 .

, , .

+1

YYYY-MM-DD, .

+4

, ,

( * 10000) + ( * 100) +

25/09/2013 (//) 20130925 , , , :

bool isDateInRange(int day, int month, int year, int startDay, int startMonth, int startYear, int endDay, int endMonth, int endYear){
    int entryDate = (year * 10000) + (month * 100) + day;
    int startDate = (startYear * 10000) + (startMonth * 100) + startDay;
    int endDate = (endYear * 10000) + (endMonth * 100) + endDay;

    if (entryDate >= startDate && entryDate <= endDate){
        return true;
    }
    else{
        return false;
    }
}
+3

, , , - , , , , // . , , 7! .

I put the Lua code http://www.cs.tufts.edu/~nr/drop/lua/cal.lua .

0
source
#include <iostream>
#include <ctime>

using namespace std;


bool isDateInRange(int day, int month, int year, int startDay, int startMonth, int startYear, int endDay, int endMonth, int endYear){
    int entryDate = (year * 10000) + (month * 100) + day;
    int startDate = (startYear * 10000) + (startMonth * 100) + startDay;
    int endDate = (endYear * 10000) + (endMonth * 100) + endDay;

    if (entryDate >= startDate && entryDate <= endDate){
        return true;
    }
    else{
        return false;
    }
}

void main()
{
    int day, month, year, startDay, startMonth, startYear, endDay, endMonth, endYear;

    // 11 June 2015
    // current date
    //day = 11; month = 6; year = 2015;
    time_t t = time(NULL);
    tm* timePtr = localtime(&t);

    day = timePtr->tm_mday;
    //cout << "day: " << day;
    month = timePtr->tm_mon + 1;
    //cout << "month: " << month;
    year = timePtr->tm_year + 1900;
    //cout << "year: " << year;

    // 1 Jan 2015
    startDay = 1; startMonth = 1; startYear = 2015;

    // 12 July 2015
    endDay = 12; endMonth = 5; endYear = 2015;

    bool isInRange = isDateInRange(day, month, year, startDay, startMonth, startYear, endDay, endMonth, endYear);

    if (isInRange)
    {
        cout << "In range " << endl;
    }
    else
    {
        cout << "Not in range " << endl;
    }
-2
source

Source: https://habr.com/ru/post/1739412/


All Articles