Ejemplo n.º 1
0
String SparkTime::ISODateUTCString(uint32_t tnow) {
  uint32_t savedTimeZone = _timezone;
  bool savedUseDST = _useDST;
  _timezone = 0;
  _useDST = false;

  String ISOString;
  ISOString += yearString(tnow);
  ISOString += "-";
  ISOString += monthString(tnow);
  ISOString += "-";
  ISOString += dayString(tnow);
  ISOString += "T";
  ISOString += hourString(tnow);
  ISOString += ":";
  ISOString += minuteString(tnow);
  ISOString += ":";
  ISOString += secondString(tnow);
  ISOString += "Z";

  _timezone = savedTimeZone;
  _useDST = savedUseDST;

  return ISOString;
}
Ejemplo n.º 2
0
String SparkTime::ISODateString(uint32_t tnow) {
  String ISOString;
  ISOString += yearString(tnow);
  ISOString += "-";
  ISOString += monthString(tnow);
  ISOString += "-";
  ISOString += dayString(tnow);
  ISOString += "T";
  ISOString += hourString(tnow);
  ISOString += ":";
  ISOString += minuteString(tnow);
  ISOString += ":";
  ISOString += secondString(tnow);

  int32_t offset = timeZoneDSTOffset(tnow)/3600L;
  // Guard against timezone problems
  if (offset>-24 && offset<24) { 
    if (offset < 0) {
      ISOString = ISOString + "-" + _digits[-offset] + "00";
    } else {
      ISOString = ISOString + "+" + _digits[offset] + "00";
    }
  }
  return ISOString;
}
Ejemplo n.º 3
0
void testTrim(void) {
    std::string firstString("Coucou je m'appelle Kafei");
    std::string firstTrim("Coucou je m'appelle Kafei");

    if (UnitTests::isNotEqual(firstString, firstTrim)) {
        printError("Trim method is not functionnal on normal string");
    }

    std::string secondString("     	 		 Coucou je suis un test 	 	 	");
    std::string secondTrim("Coucou je suis un test");

    if (UnitTests::isNotEqual(firstString, firstTrim)) {
        printError("Trim method is not triming string");
    }
}
Ejemplo n.º 4
0
	static void testAll(World &world)
	{
		auto sourceString = reinterpret_cast<const std::uint8_t*>(u8"Hello world everyone!");
		const size_t sourceLength = 21;

		// Create a source bytevector
		alloc::BytevectorRef origBv(world, BytevectorCell::fromData(world, sourceString, sourceLength));

		// Create a direct copy
		alloc::BytevectorRef copyBv(world, origBv->copy(world));
		ASSERT_TRUE(sharedByteArrayFor(origBv) == sharedByteArrayFor(copyBv));

		// Set an byte of the copy
		ASSERT_TRUE(copyBv->setByteAt(0, 4));
		// The sharing should now be broken
		ASSERT_FALSE(sharedByteArrayFor(origBv) == sharedByteArrayFor(copyBv));

		// Create a copy from appending a single bytevector
		alloc::BytevectorRef appendedBv(world, BytevectorCell::fromAppended(world, {origBv}));
		ASSERT_TRUE(sharedByteArrayFor(origBv) == sharedByteArrayFor(appendedBv));

		// Replace part of the byte array
		ASSERT_TRUE(appendedBv->replace(3, origBv, 0, 1));
		// Sharing should now be broken
		ASSERT_FALSE(sharedByteArrayFor(origBv) == sharedByteArrayFor(appendedBv));

		// Create a string from the bytevector
		alloc::StringRef origString(world, origBv->utf8ToString(world));
		ASSERT_TRUE(sharedByteArrayFor(origBv) == sharedByteArrayFor(origString));

		// Create a string as a copy
		alloc::StringRef copyString(world, origString->copy(world));
		ASSERT_TRUE(sharedByteArrayFor(origString) == sharedByteArrayFor(copyString));

		// Set a character in the string
		ASSERT_TRUE(copyString->setCharAt(5, UnicodeChar('!')));
		// Sharing should now be broken
		ASSERT_FALSE(sharedByteArrayFor(origString) == sharedByteArrayFor(copyString));

		// Create a string from appending a single string
		alloc::StringRef appendedString(world, StringCell::fromAppended(world, {origString}));
		ASSERT_TRUE(sharedByteArrayFor(origString) == sharedByteArrayFor(appendedString));

		// Fill the string
		ASSERT_TRUE(appendedString->fill(UnicodeChar(4)));
		// Sharing should now be broken
		ASSERT_FALSE(sharedByteArrayFor(origString) == sharedByteArrayFor(appendedString));

		// Create a symbol from the appended string
		alloc::SymbolRef symbol(world, SymbolCell::fromString(world, appendedString));
		ASSERT_TRUE(sharedByteArrayFor(appendedString) == sharedByteArrayFor(symbol));

		// Writing to the string again should break sharing
		// Symbols are immutable so breaking cannot happen from the symbol side
		appendedString->replace(1, origString, 0, 1);
		ASSERT_FALSE(sharedByteArrayFor(appendedString) == sharedByteArrayFor(symbol));

		//
		// Test a grand tour of string ->  symbol -> string -> bytevector -> string
		//
		
		alloc::StringRef firstString(world, StringCell::fromUtf8StdString(world, u8"Hello world everyone!"));
		alloc::SymbolRef firstSymbol(world, SymbolCell::fromString(world, firstString));
		alloc::StringRef secondString(world, StringCell::fromSymbol(world, firstSymbol));
		alloc::BytevectorRef firstBv(world, secondString->toUtf8Bytevector(world));
		alloc::StringRef thirdString(world, firstBv->utf8ToString(world));

		ASSERT_TRUE(sharedByteArrayFor(firstString) == sharedByteArrayFor(thirdString));
	}
Ejemplo n.º 5
0
JSObject* IntlDateTimeFormat::resolvedOptions(ExecState& exec)
{
    VM& vm = exec.vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    // 12.3.5 Intl.DateTimeFormat.prototype.resolvedOptions() (ECMA-402 2.0)
    // The function returns a new object whose properties and attributes are set as if constructed by an object literal assigning to each of the following properties the value of the corresponding internal slot of this DateTimeFormat object (see 12.4): locale, calendar, numberingSystem, timeZone, hour12, weekday, era, year, month, day, hour, minute, second, and timeZoneName. Properties whose corresponding internal slots are not present are not assigned.
    // Note: In this version of the ECMAScript 2015 Internationalization API, the timeZone property will be the name of the default time zone if no timeZone property was provided in the options object provided to the Intl.DateTimeFormat constructor. The previous version left the timeZone property undefined in this case.
    if (!m_initializedDateTimeFormat) {
        initializeDateTimeFormat(exec, jsUndefined(), jsUndefined());
        ASSERT_UNUSED(scope, !scope.exception());
    }

    JSObject* options = constructEmptyObject(&exec);
    options->putDirect(vm, vm.propertyNames->locale, jsNontrivialString(&exec, m_locale));
    options->putDirect(vm, vm.propertyNames->calendar, jsNontrivialString(&exec, m_calendar));
    options->putDirect(vm, vm.propertyNames->numberingSystem, jsNontrivialString(&exec, m_numberingSystem));
    options->putDirect(vm, vm.propertyNames->timeZone, jsNontrivialString(&exec, m_timeZone));

    if (m_weekday != Weekday::None)
        options->putDirect(vm, vm.propertyNames->weekday, jsNontrivialString(&exec, ASCIILiteral(weekdayString(m_weekday))));

    if (m_era != Era::None)
        options->putDirect(vm, vm.propertyNames->era, jsNontrivialString(&exec, ASCIILiteral(eraString(m_era))));

    if (m_year != Year::None)
        options->putDirect(vm, vm.propertyNames->year, jsNontrivialString(&exec, ASCIILiteral(yearString(m_year))));

    if (m_month != Month::None)
        options->putDirect(vm, vm.propertyNames->month, jsNontrivialString(&exec, ASCIILiteral(monthString(m_month))));

    if (m_day != Day::None)
        options->putDirect(vm, vm.propertyNames->day, jsNontrivialString(&exec, ASCIILiteral(dayString(m_day))));

    if (m_hour != Hour::None) {
        options->putDirect(vm, vm.propertyNames->hour, jsNontrivialString(&exec, ASCIILiteral(hourString(m_hour))));
        options->putDirect(vm, vm.propertyNames->hour12, jsBoolean(m_hour12));
    }

    if (m_minute != Minute::None)
        options->putDirect(vm, vm.propertyNames->minute, jsNontrivialString(&exec, ASCIILiteral(minuteString(m_minute))));

    if (m_second != Second::None)
        options->putDirect(vm, vm.propertyNames->second, jsNontrivialString(&exec, ASCIILiteral(secondString(m_second))));

    if (m_timeZoneName != TimeZoneName::None)
        options->putDirect(vm, vm.propertyNames->timeZoneName, jsNontrivialString(&exec, ASCIILiteral(timeZoneNameString(m_timeZoneName))));

    return options;
}