static EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatFuncFormatDateTime(ExecState* state)
{
    // 12.3.4 DateTime Format Functions (ECMA-402 2.0)
    // 1. Let dtf be the this value.
    // 2. Assert: Type(dtf) is Object and dtf has an [[initializedDateTimeFormat]] internal slot whose value is true.
    IntlDateTimeFormat* format = jsCast<IntlDateTimeFormat*>(state->thisValue());

    JSValue date = state->argument(0);
    double value;

    // 3. If date is not provided or is undefined, then
    if (date.isUndefined()) {
        // a. Let x be %Date_now%().
        value = JSValue::decode(dateNow(state)).toNumber(state);
    } else {
        // 4. Else
        // a. Let x be ToNumber(date).
        value = date.toNumber(state);
        // b. ReturnIfAbrupt(x).
        if (state->hadException())
            return JSValue::encode(jsUndefined());
    }

    // 5. Return FormatDateTime(dtf, x).
    return JSValue::encode(format->format(*state, value));
}
예제 #2
0
EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatFuncFormatDateTime(ExecState* state)
{
    // 12.3.4 DateTime Format Functions (ECMA-402 2.0)
    // 1. Let dtf be the this value.
    IntlDateTimeFormat* format = jsDynamicCast<IntlDateTimeFormat*>(state->thisValue());
    // 2. Assert: Type(dtf) is Object and dtf has an [[initializedDateTimeFormat]] internal slot whose value is true.
    if (!format)
        return JSValue::encode(throwTypeError(state));

    JSValue date = state->argument(0);
    double value;

    // 3. If date is not provided or is undefined, then
    if (date.isUndefined()) {
        // a. Let x be %Date_now%().
        value = JSValue::decode(dateNow(state)).toNumber(state);
    } else {
        // 4. Else
        // a. Let x be ToNumber(date).
        value = date.toNumber(state);
        // b. ReturnIfAbrupt(x).
        if (state->hadException())
            return JSValue::encode(jsUndefined());
    }

    // 5. Return FormatDateTime(dtf, x).

    // 12.3.4 FormatDateTime abstract operation (ECMA-402 2.0)

    // 1. If x is not a finite Number, then throw a RangeError exception.
    if (!std::isfinite(value))
        return JSValue::encode(throwRangeError(state, ASCIILiteral("date value is not finite in DateTimeFormat.format()")));

    // FIXME: implement 2 - 9

    // Return new Date(value).toString() until properly implemented.
    VM& vm = state->vm();
    JSGlobalObject* globalObject = state->callee()->globalObject();
    DateInstance* d = DateInstance::create(vm, globalObject->dateStructure(), value);
    return JSValue::encode(JSValue(d).toString(state));
}
예제 #3
0
/***************************************************
ParseString
	The ParseString function pulls the text out of a 
	cell, and attempts to parse it into a mailItem struct.
	It will continue trying to find valid values until
	it fails, and then return the struct with whatever
	values it could find.  Naturally, it's always the
	intention that all the required data is present.
Params:
	item	- mailitem to turn into a string
	col		- column to store string to
	row		- row to store string to
	cell	- cell that is being set
Return
	<none>
****************************************************/
CUGCTMail::mailItem CUGCTMail::ParseString(CUGCell * cell)
{
	mailItem item;

	CString sItem;
	cell->GetText(&sItem);

	LPTSTR text = sItem.GetBuffer(sItem.GetLength());
	sItem.ReleaseBuffer();

	TCHAR * nextToken;
	TCHAR * s = UGStr::tcstok(text, _T("\v"), &nextToken);

	if (s)
	{
		item.leftIcon = _ttoi(s);
		s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
		if (s)
		{
			item.sender = s;
			s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
			if (s)
			{
				time_t ltime;
				time(&ltime);

				CTime dateNow(ltime);

				item.date = CTime((time_t)_ttoi(s));

				if (item.date.GetDay() == dateNow.GetDay() &&
					item.date.GetMonth() == dateNow.GetMonth() &&
					item.date.GetYear() == dateNow.GetYear())
				{
					item.dateString = item.date.Format("%I:%M %p");
				}
				else
				{
					item.dateString = item.date.Format("%a %I:%M %p");
				}

				s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
				if (s)
				item.subject = s;
				s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
				if (s)
				{
					item.rightIcon = _ttoi(s);
					s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
					if (s)
					{
						item.isRead = (_ttoi(s) > 0);
						s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
						if (s)
						{
							item.mail = s;
							s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
							if (s)
							{
								// It is acceptable for the attachment path to be empty
								item.didParseOK = true;
								item.size = _ttoi(s);
								s = UGStr::tcstok(NULL, _T("\v"), &nextToken);
								if (s)
								{
									item.attachmentPath = s;
								}
							}
						}
					}
				}
			}
		}

	}
	else
	{
		item.subject = text;
	}

	return item;
}
boost::posix_time::ptime DateTimeEventsManager::GetEventStartTime(const DateTimeEvent* pEvent) const
{
	boost::posix_time::ptime resultTime;

	switch (pEvent->GetType())
	{
	case DateTimeEvent::typeOnce:
		{
			boost::posix_time::ptime scheduledTime(pEvent->GetDate(), pEvent->GetTime());
			const boost::posix_time::time_duration d = boost::posix_time::second_clock::local_time() - scheduledTime;

			// This may happen after player startup if there is an event with date/time in the past.
			if (d.total_seconds() > 1)
			{
				scheduledTime = boost::posix_time::not_a_date_time;
			}

			resultTime = scheduledTime;
		}
		break;

	case DateTimeEvent::typeDaily:
		{
			boost::posix_time::ptime startTime(boost::gregorian::day_clock::local_day(), pEvent->GetTime());
			
			if (boost::posix_time::second_clock::local_time() >= startTime)
				startTime += boost::gregorian::days(1);

			resultTime = startTime;
		}
		break;

	case DateTimeEvent::typeWeekly:
		{
			boost::gregorian::date dateNow(boost::gregorian::day_clock::local_day());

			int currentDayOfWeek = dateNow.day_of_week().as_number();

			if (currentDayOfWeek == 0)
				currentDayOfWeek = 7;

			--currentDayOfWeek; // Format 0 = Mon, 1 = Tue, .. , 6 = Sun
			
			boost::gregorian::date weekStartDate =
				dateNow - boost::gregorian::date_duration(currentDayOfWeek);

			std::vector<boost::posix_time::ptime> times;

			for (int i = 0; i < 7; ++i)
				if (pEvent->GetWeekDays() & (1 << i))
				{
					boost::posix_time::ptime startTime(
						weekStartDate + boost::gregorian::date_duration(i), pEvent->GetTime());

					if (boost::posix_time::second_clock::local_time() >= startTime)
						startTime += boost::gregorian::days(7);

					times.push_back(startTime);
				}

			std::sort(times.begin(), times.end());

			_ASSERTE(!times.empty());
			resultTime = times[0];
		}
		break;
	}

	return resultTime;
}