Example #1
0
    // dateS minus fixed day, dateS's format(20130915)
    bool TimeFormat::jianDay(const std::string& dateS, std::string& dateD, const int fixed)
    {
        if (dateS.length() != 8)
        {
            return false;
        }

        int year = 0;
        int month = 0;
        int day = 0;
        try
        {
            year = boost::lexical_cast<int>(dateS.substr(0,4));
            month = boost::lexical_cast<int>(dateS.substr(4,2));
            day = boost::lexical_cast<int>(dateS.substr(6,2));
        }
        catch (const boost::bad_lexical_cast&)
        {
            return false;
        }

        if (year <= 0 || month <= 0 || month > 12 || day <= 0 || day > 31)
        {
            return false;
        }

        int fixedT = fixed;
        while (fixedT)
        {
            if (day <= fixedT)
            {
                fixedT -= day;

                if (month > 1)
                {
                    --month;
                    day = DAYOFMONTH[month];
                    if (month == 2 && LEAP_YEAR(year))
                    {
                        day += 1;
                    }
                }
                else
                {
                    year -= 1;
                    month = 12;
                    day = 31;
                }
            }
            else
            {
                day -= fixedT;
                fixedT = 0;
                break;
            }
        }

        dateD = MAKE_DATE(year, month, day);
        return true;
    }
Example #2
0
/*----------------------------------------------------------------------------*/
static long timer_to_date(time_t time_secs)
{
    struct tm *time_struct;

    if (time_secs == 0) {
        return 0;
    } else {
        /*  Convert into a long value CCYYMMDD */
        time_struct = localtime (&time_secs);
        if (time_struct) {
            time_struct-> tm_year += 1900;
            return (MAKE_DATE (    time_struct-> tm_year / 100,
                                time_struct-> tm_year % 100,
                                time_struct-> tm_mon + 1,
                                time_struct-> tm_mday));
        } else {
            return (19700101);
        }
    }
}
Example #3
0
/*
 * Function name: export_mail
 * Description  : With this function the mail-folder of a player can be
 *                exported to a file.
 * Arguments    : string name - the lower case name of the player whose
 *                              mailbox is to be exported.
 *                string path - the name of the output file.
 * Returns      : int 1/0 - success/failure.
 */
static int
export_mail(string name, string path)
{
    mapping mail;
    mixed   messages;
    int     index;
    int     size;
    string  text;

    /* Get the output path and test its valitity by writing the header. */
    path = FTPATH(this_player()->query_path(), path);
    if (file_size(path) != -1)
    {
	notify_fail("File " + path + " already exists.\n");
	return 0;
    }

    /* This may fail if there is no such directory, for instance. */
    if (!write_file(path, "Mailbox of: " + capitalize(name) +
	"\nPrinted at: " + ctime(time()) + "\n\n"))
    {
	notify_fail("Failed to write header of " + path + "\n");
	return 0;
    }

    /* Read the mail file. */
    mail = restore_mail(name);
    if (!mappingp(mail))
    {
	notify_fail("No correct mail folder for player " + name + ".\n");
	return 0;
    }

    /* Loop over all messages. */
    messages = mail[MAIL_MAIL];
    index = -1;
    size = sizeof(messages);
    while(++index < size)
    {
	mail = restore_message(messages[index][MAIL_DATE]);
	
	text = "Message: " + (index + 1) + "\nFrom   : " +
	      messages[index][MAIL_FROM] + "\n" +
	      (messages[index][MAIL_REPLY] ? "Reply  : " : "Subject: ") +
	      messages[index][MAIL_SUBJ] + "\n";
	
	if (mail[MSG_TO] != capitalize(name))
	{
	    text += HANGING_INDENT("To     : " +
		COMPOSITE_WORDS(explode(mail[MSG_TO], ",")), 9, 1);
	}
	
	if (mail[MSG_CC] != "")
	{
	    text += HANGING_INDENT("CC     : " +
		COMPOSITE_WORDS(explode(mail["cc"], ",")), 9, 1);
	}

	/* Write the message to file and print a sequence number to the
	 * wizard. Notice that the index of the loop is also increased in
	 * this write-statement.
	 */	
	write_file(path, text + "Date   : " +
            MAKE_DATE(messages[index][MAIL_DATE]) + " " +
            DATE_YEAR(messages[index][MAIL_DATE]) +
	    "\n\n" + wrap_text(mail[MSG_BODY]) + "\n\n");
    }

    write("Mail folder written for " + capitalize(name) + ".\nFilename: " +
	path + "\n");
    return 1;
}