Esempio n. 1
0
TEST(gnc_datetime_constructors, test_gncdate_end_constructor)
{
    const ymd aymd = { 2046, 11, 06 };
    GncDateTime atime(GncDate(aymd.year, aymd.month, aymd.day), DayPart::end);
    //Skipping timezone information as this can't be controlled.
    EXPECT_EQ(atime.format("%d-%m-%Y %H:%M:%S"), "06-11-2046 23:59:59");
}
Esempio n. 2
0
TEST(gnc_datetime_constructors, test_gncdate_start_constructor)
{
    const ymd aymd = { 2017, 04, 20 };
    GncDateTime atime(GncDate(aymd.year, aymd.month, aymd.day), DayPart::start);
    //Skipping timezone information as this can't be controlled.
    EXPECT_EQ(atime.format("%d-%m-%Y %H:%M:%S"), "20-04-2017 00:00:00");
}
Esempio n. 3
0
//This is a bit convoluted because it uses GncDate's GncDateImpl constructor and year_month_day() function. There's no good way to test the former without violating the privacy of the implementation.
TEST(gnc_datetime_functions, test_date)
{
    GncDateTime atime(2394187200); //2045-11-13 12:00:00 Z
    GncDate gncd = atime.date();
    auto ymd = gncd.year_month_day();
    EXPECT_EQ(ymd.year, 2045);
    EXPECT_EQ(ymd.month, 11);
    EXPECT_EQ(ymd.day, 13);
}
Esempio n. 4
0
char    *_FARFUNC asctime(const struct tm *tmPtr)
{
#if !defined( _RTLDLL )
    static char a[26];
#endif
    int end;
    _QRTLDataBlock;

    end = atime( _QRTLInstanceData(a), tmPtr );
    _QRTLInstanceData(a)[end++] = '\n';        //  add terminating newline
    _QRTLInstanceData(a)[end] = '\0';

    return(_QRTLInstanceData(a));
}
Esempio n. 5
0
TEST(gnc_datetime_constructors, test_struct_tm_constructor)
{
#ifdef HAVE_STRUCT_TM_GMTOFF
    const struct tm tm {0, 0, 12, 13, 10, 145, 0, 0, 0, NULL, 0 };
#else
    const struct tm tm {0, 0, 12, 13, 10, 145, 0, 0, 0 };
#endif

    const time64 time = 2394187200; //2045-11-13 12:00:00 Z
    GncDateTime atime(tm);
    EXPECT_EQ(static_cast<time64>(atime), time);
    const struct tm tm1 = static_cast<struct tm>(atime);
    EXPECT_EQ(tm1.tm_year, tm.tm_year);
    EXPECT_EQ(tm1.tm_mon, tm.tm_mon);
    EXPECT_EQ(tm1.tm_mday, tm.tm_mday);
// We have to contort this a bit to handle offsets > 12, e.g. New Zealand during DST.
    EXPECT_EQ((24 + tm1.tm_hour - atime.offset() / 3600) % 24, tm.tm_hour);
    EXPECT_EQ(tm1.tm_min, tm.tm_min);
}
Esempio n. 6
0
void stats_plusminususer(Chan *chan, int plusminus)
{
	ChanStats *stats;
	ChanUser *cu;

	if (!(stats = chan->stats))
	{
		set_mallocdoer(stats_plusminususer);
		chan->stats = stats = (ChanStats*)Calloc(sizeof(ChanStats)); /* Calloc sets memory to 0 */
		for(cu=chan->users;cu;cu=cu->next)
			stats->users++;
		stats->userpeak = stats->users;
		stats->userlow = stats->users;
		stats->lastuser = now;
		stats->flags = CSTAT_PARTIAL;
	}

	/*
	 *  add (number of users until now * seconds since last user entered/left)
	 */
	stats->userseconds += stats->users * (now - stats->lastuser);

	stats->lastuser = now;
	stats->users += plusminus;	/* can be both negative (-1), zero (0) and positive (+1) */

	if (stats->userpeak < stats->users)
		stats->userpeak = stats->users;
	if (stats->userlow > stats->users)
		stats->userlow = stats->users;

#ifdef DEBUG
	debug("(stats_plusminususer) %s: %i users, %i userseconds, %i high, %i low; %s (%lu)\n",
		chan->name,stats->users,stats->userseconds,stats->userpeak,stats->userlow,
		atime(stats->lastuser),stats->lastuser);
#endif /* DEBUG */
}
Esempio n. 7
0
size_t WINAPI StrFTime(string &strDest, const wchar_t *Format,const tm *t)
{
	if (CurLang==-1 && Lang.IsLanguageLoaded())
		PrepareStrFTime();

	// меняем язык.
	CurLang=0;
	size_t Len;

	for (Len=1; *Format; Format++)
	{
		if (*Format!=L'%')
		{
			Len++;
			const wchar_t Text[]={*Format,0};
			strDest+=Text;
		}
#if 1
		else
		{
			string strBuf;

			switch (*++Format)
			{
				case L'L':
					CurLang=!CurLang;
					continue;
					// Краткое имя дня недели (Sun,Mon,Tue,Wed,Thu,Fri,Sat)
					// abbreviated weekday name
				case L'a':
					strBuf=AWeekday[CurLang][!WeekFirst?((t->tm_wday+6)%7):(!t->tm_wday?6:t->tm_wday-1)];
					break;
					// Полное имя дня недели
					// full weekday name
				case L'A':
					strBuf=Weekday[CurLang][!WeekFirst?((t->tm_wday+6)%7):(!t->tm_wday?6:t->tm_wday-1)];
					break;
					// Краткое имя месяца (Jan,Feb,...)
					// abbreviated month name
				case L'h':
				case L'b':
					strBuf=AMonth[CurLang][t->tm_mon];
					break;
					// Полное имя месяца
					// full month name
				case L'B':
					strBuf=Month[CurLang][t->tm_mon];
					break;
					//Дата и время в формате WDay Mnt  Day HH:MM:SS yyyy
					//appropriate date and time representation
				case L'c':
					atime(strBuf,t);
					break;
					// Столетие как десятичное число (00 - 99). Например, 1992 => 19
				case L'C':
					strBuf.Format(L"%02d",(t->tm_year+1900)/100);
					break;
					// day of month, blank padded
				case L'e':
					// Две цифры дня месяца (01 - 31)
					// day of the month, 01 - 31
				case L'd':
					strBuf.Format(*Format==L'e'?L"%2d":L"%02d",t->tm_mday);
					break;
					// hour, 24-hour clock, blank pad
				case L'k':
					// Две цифры часа (00 - 23)
					// hour, 24-hour clock, 00 - 23
				case L'H':
					strBuf.Format(*Format==L'k'?L"%2d":L"%02d",t->tm_hour);
					break;
					// hour, 12-hour clock, 1 - 12, blank pad
				case L'l':
					// Две цифры часа (01 - 12)
					// hour, 12-hour clock, 01 - 12
				case L'I':
				{
					int I=t->tm_hour%12;

					if (!I)
						I=12;

					strBuf.Format(*Format==L'l'?L"%2d":L"%02d",I);
					break;
				}
				// Три цифры дня в году (001 - 366)
				// day of the year, 001 - 366
				case L'j':
					strBuf.Format(L"%03d",t->tm_yday+1);
					break;
					// Две цифры месяца, как десятичное число (1 - 12)
					// month, 01 - 12
				case L'm':
				{
					// %mh - Hex month digit
					// %m0 - ведущий 0
					const wchar_t *fmt=Format[1]==L'h'?L"%X":Format[1]==L'0'?L"%02d":L"%d";

					if (fmt[1]!=L'd')
						Format++;

					strBuf.Format(fmt,t->tm_mon+1);
					break;
				}
				// Две цифры минут (00 - 59)
				// minute, 00 - 59
				case L'M':
					strBuf.Format(L"%02d",t->tm_min);
					break;
					// AM или PM
					// am or pm based on 12-hour clock
				case L'p':
					strBuf=(t->tm_hour/12)?L"PM":L"AM";
					break;
					// Две цифры секунд (00 - 59)
					// second, 00 - 59
				case L'S':
					strBuf.Format(L"%02d",t->tm_sec);
					break;
					// День недели где 0 - Воскресенье (Sunday) (0 - 6)
					// weekday, Sunday == 0, 0 - 6
				case L'w':
					strBuf.Format(L"%d",t->tm_wday);
					break;
					// Две цифры номера недели, где Воскресенье (Sunday)
					//   является первым днем недели (00 - 53)
					// week of year, Sunday is first day of week
				case L'U':
					// Две цифры номера недели, где Понедельник (Monday)
					//    является первым днем недели (00 - 53)
					// week of year, Monday is first day of week
				case L'W':
				{
					int I=t->tm_wday-(t->tm_yday%7);

					//I = (chr == 'W'?(!WeekFirst?((t->tm_wday+6)%7):(t->tm_wday? t->tm_wday-1:6)):(t->tm_wday)) - (t->tm_yday % 7);
					if (I<0)
						I+=7;

					strBuf.Format(L"%02d",(t->tm_yday+I-(*Format==L'W'))/7);
					break;
				}
				// date as dd-bbb-YYYY
				case L'v':
					// Дата в формате mm.dd.yyyy
					// appropriate date representation
				case L'D':
				case L'x':
					st_time(strBuf,t,*Format);
					break;
					// Время в формате HH:MM:SS
					// appropriate time representation
				case L'T':
				case L'X':
				{
					int TimeSeparator=GetTimeSeparator();
					strBuf.Format(L"%02d%c%02d%c%02d",t->tm_hour,TimeSeparator,t->tm_min,TimeSeparator,t->tm_sec);
					break;
				}
				// Две цифры года без столетия (00 to 99)
				// year without a century, 00 - 99
				case L'y':
					strBuf.Format(L"%02d",t->tm_year%100);
					break;
					// Год со столетием (19yy-20yy)
					// year with century
				case L'Y':
					strBuf.Format(L"%d",1900+t->tm_year);
					break;
					// Имя часового пояса или пусто, если часовой пояс не задан
				case L'Z':
					strBuf.Format(L"%+03d%02d",-(_timezone/3600),-(_timezone/60)%60);
					//Ptr = _tzname[ t->tm_isdst ];
					break;
					// same as \n
				case L'n':
					strBuf=L"\n";
					break;
					// same as \t
				case L't':
					strBuf=L"\t";
					break;
				case L'%':
					strBuf=L"%";
					break;
					// time as %I:%M:%S %p
				case L'r':
					StrFTime(strBuf,L"%I:%M:%S %p",t);
					break;
					// time as %H:%M
				case L'R':
					StrFTime(strBuf,L"%H:%M",t);
					break;
					// week of year according ISO 8601
				case L'V':
					strBuf.Format(L"%02d",iso8601wknum(t));
					break;
			}

			strDest+=strBuf;
			Len+=strBuf.GetLength();
		}
#endif
	}

	if (*Format)
		return 0;

	return Len-1;
}
Esempio n. 8
0
size_t _FARFUNC strftime( char *s, size_t maxsize, const char *fmt, const struct tm *t )
  {
  char buf[ 25 ];

  char *p = buf;
  int i, len;

  for( len = 1; len < maxsize && *fmt; ++fmt, p = buf )
    {
    if( *fmt != '%' )
      {
      ++len;
      *s++ = *fmt;
      }
    else
      {
      strcpy( buf, "00" );

      switch( *++fmt )
        {
        case 'a':
            p = SWeekday[t->tm_wday];
            break;
        case 'A':
            p = LWeekday[t->tm_wday];
            break;
        case 'b':
            p = SMonth[t->tm_mon];
            break;
        case 'B':
            p = LMonth[t->tm_mon];
            break;
        case 'c':
            atime( p, t );
            break;
        case 'd':
            __utoa( t->tm_mday, buf + (t->tm_mday < 10) );
            break;
        case 'H':
            __utoa( t->tm_hour, buf + (t->tm_hour < 10) );
            break;
        case 'I':
            i = t->tm_hour % 12;
            if (i == 0)
                i = 12;
            __utoa( i, buf + (i < 10) );
            break;
        case 'j':
            i = t->tm_yday + 1;
            __utoa( i, buf + (i < 10) + (i < 100) );
            break;
        case 'm':
            i = t->tm_mon + 1;
            __utoa( i, buf + (i < 10) );
            break;
        case 'M':
            __utoa( t->tm_min, buf + (t->tm_min < 10) );
            break;
        case 'p':
            p = AmPm[ t->tm_hour / 12 ];
            break;
        case 'S':
            __utoa( t->tm_sec, buf + (t->tm_sec < 10) );
            break;
        case 'U':
            i = t->tm_wday - (t->tm_yday % 7);
            if( i < 0 )
                i += 7;
            i = (t->tm_yday + i) / 7;
            __utoa( i, buf + (i < 10) );
            break;
        case 'w':
            __utoa( t->tm_wday, buf );
            break;
        case 'W':
            i = t->tm_wday - (t->tm_yday % 7);
            if( i < 0 )
                i += 7;
            i = (t->tm_yday + i - 1) / 7;
            __utoa( i, buf + (i < 10) );
            break;
        case 'x':
            strcpy( buf, SWeekday[t->tm_wday] );
            strcat( buf, " " );
            strcat( buf, SMonth[t->tm_mon] );
            strcat( buf, " " );
            __utoa( t->tm_mday, buf + strlen( buf ) );
            strcat( buf, ", " );
            __utoa( t->tm_year + 1900, buf + strlen( buf ) );
            break;

        case 'X':
            __utoa( t->tm_hour, buf + (t->tm_hour < 10) );
            strcat( buf, ":0" );
            __utoa( t->tm_min, buf + strlen( buf ) - (t->tm_min > 9) );
            strcat( buf, ":0" );
            __utoa( t->tm_sec, buf + strlen( buf ) - (t->tm_sec > 9) );
            break;
        case 'y':
            i = t->tm_year % 100;
            __utoa( i, buf + (i < 10) );
            break;
        case 'Y':
            __utoa( 1900 + t->tm_year, buf );
            break;
        case 'Z':
            p = tzname[ t->tm_isdst ];
            break;
        case '%':
            p = "%";
        }

      i = min( strlen( p ), maxsize - len );
      strncpy( s, p, i );
      len += i;
      s += i;
      }
    }

  *s = '\0';

  if( *fmt )  return( 0 );
  else        return( len - 1 );
  }
Esempio n. 9
0
/*	m_gqline - Global Q:Line
**	parv[0] = sender
**	parv[1] = nickname mask
**	parv[2] = Optional expiration time
**	parv[3] = reason
*/
static int m_gqline(aClient *cptr, aClient *sptr, int parc, char* parv[])
{
    TS secs;
    int whattodo = 0;
    int i;
    aClient *acptr = NULL;
    char *mask = NULL;
    char mo[1024], mo2[1024];
    char *p;
    char *tkllayer[9] = {
        me.name,	/* 0 = Server Name */
        NULL,		/* 1 = + / - */
        "Q",		/* 2 = Q - Global Q:Line */
        "*",		/* 3 = * = normal qline, H = hold */
        NULL,		/* 4 = Nickname mask */
        NULL,		/* 5 = setby */
        "0",		/* 6 = expire ts */
        NULL,		/* 7 = set ts */
        "no reason"	/* 8 = reason */
    };
    struct tm *t = NULL;
    if (IsServer(sptr)) return 0;
    if (!OPCanTKL(sptr) || !IsOper(sptr))
    {
        sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, sptr->name);
        return 0;
    }
    if (parc == 1)
    {
        tkl_stats(sptr, TKL_NICK|TKL_GLOBAL, NULL);
        sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, sptr->name, 'Q');
        return 0;
    }
    mask = parv[1];
    if (*mask == '-') {
        whattodo = 1;
        mask++;
    }
    else if (*mask == '+') {
        whattodo = 0;
        mask++;
    }
    if (!whattodo) {
        char c;
        i = 0;
        for (p = mask; *p; p++) if (*p != '*' && *p != '?') i++;
        if (i < 4) {
            sendto_one(sptr, ":%s NOTICE %s :*** [error] Too broad mask", me.name, sptr->name);
            return 0;
        }
    }
    tkl_check_expire(NULL);
    secs = 0;
    if (whattodo == 0 && (parc > 3))
    {
        secs = atime(parv[2]);
        if (secs < 0) {
            sendto_one(sptr, ":%s NOTICE %s :*** [error] Specified time out of range", me.name, sptr->name);
            return 0;
        }
    }
    tkllayer[1] = whattodo == 0 ? "+" : "-";
    tkllayer[4] = mask;
    tkllayer[5] = make_nick_user_host(sptr->name, sptr->user->username, GetHost(sptr));
    if (whattodo == 0)
    {
        if (secs == 0)
        {
            if (DEFAULT_BANTIME && (parc <= 3))
                ircsprintf(mo, "%li", DEFAULT_BANTIME + TStime());
            else
                ircsprintf(mo, "%li", secs);
        }
        else
            ircsprintf(mo, "%li", secs + TStime());
        ircsprintf(mo2, "%li", TStime());
        tkllayer[6] = mo;
        tkllayer[7] = mo2;
        if (parc > 3) {
            tkllayer[8] = parv[3];
        } else if (parc > 2) {
            tkllayer[8] = parv[2];
        }
        i = atol(mo);
        t = gmtime((TS*)&i);
        if (!t)
        {
            sendto_one(sptr, ":%s NOTICE %s :*** [error] Specified time is out of range", me.name, sptr->name);
            return 0;
        }
        m_tkl(&me, &me, 9, tkllayer);
    }
    else {
        m_tkl(&me, &me, 6, tkllayer);
    }
    return 0;
}
Esempio n. 10
0
TEST(gnc_datetime_functions, test_format_zulu)
{
    GncDateTime atime(2394187200); //2045-11-13 12:00:00 Z
    //Date only to finesse timezone issues. It will still fail in +12 DST.
    EXPECT_EQ(atime.format_zulu("%d-%m-%Y %H:%M:%S"), "13-11-2045 12:00:00");
}
Esempio n. 11
0
TEST(gnc_datetime_constructors, test_gncdate_neutral_constructor)
{
    const ymd aymd = { 2017, 04, 20 };
    GncDateTime atime(GncDate(aymd.year, aymd.month, aymd.day), DayPart::neutral);
    EXPECT_EQ(atime.format("%d-%m-%Y %H:%M:%S %z"), "20-04-2017 10:59:00 UTC");
}
Esempio n. 12
0
TEST(gnc_datetime_constructors, test_time64_constructor)
{
    const time64 time = 2394187200; //2045-11-13 12:00:00 Z
    GncDateTime atime(time);
    EXPECT_EQ(static_cast<time64>(atime), time);
}