Search in sources :

Example 16 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class JCardWriterTest method createExample.

public static VCard createExample() {
    VCard vcard = new VCard();
    vcard.setFormattedName("SimonPerreault");
    StructuredName n = new StructuredName();
    n.setFamily("Perreault");
    n.setGiven("Simon");
    n.getSuffixes().add("ing.jr");
    n.getSuffixes().add("M.Sc.");
    vcard.setStructuredName(n);
    Birthday bday = new Birthday(PartialDate.builder().month(2).date(3).build());
    vcard.setBirthday(bday);
    Anniversary anniversary = new Anniversary(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).second(0).offset(new UtcOffset(false, -5, 0)).build());
    vcard.setAnniversary(anniversary);
    vcard.setGender(Gender.male());
    vcard.addLanguage("fr").setPref(1);
    vcard.addLanguage("en").setPref(2);
    vcard.setOrganization("Viagenie").setType("work");
    Address adr = new Address();
    adr.setExtendedAddress("SuiteD2-630");
    adr.setStreetAddress("2875Laurier");
    adr.setLocality("Quebec");
    adr.setRegion("QC");
    adr.setPostalCode("G1V2M2");
    adr.setCountry("Canada");
    adr.getTypes().add(AddressType.WORK);
    vcard.addAddress(adr);
    TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
    Telephone tel = new Telephone(telUri);
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.VOICE);
    tel.setPref(1);
    vcard.addTelephoneNumber(tel);
    tel = new Telephone(new TelUri.Builder("+1-418-262-6501").build());
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.CELL);
    tel.getTypes().add(TelephoneType.VOICE);
    tel.getTypes().add(TelephoneType.VIDEO);
    tel.getTypes().add(TelephoneType.TEXT);
    vcard.addTelephoneNumber(tel);
    vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
    Geo geo = new Geo(46.772673, -71.282945);
    geo.setType("work");
    vcard.setGeo(geo);
    Key key = new Key("http://www.viagenie.ca/simon.perreault/simon.asc", null);
    key.setType("work");
    vcard.addKey(key);
    vcard.setTimezone(new Timezone(new UtcOffset(false, -5, 0)));
    vcard.addUrl("http://nomis80.org").setType("home");
    return vcard;
}
Also used : Timezone(ezvcard.property.Timezone) Address(ezvcard.property.Address) Telephone(ezvcard.property.Telephone) Anniversary(ezvcard.property.Anniversary) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Geo(ezvcard.property.Geo) UtcOffset(ezvcard.util.UtcOffset) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Key(ezvcard.property.Key)

Example 17 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class XCardReaderTest method read_rfc6351_example.

@Test
public void read_rfc6351_example() throws Throwable {
    VCardAsserter asserter = read("rfc6351-example.xml");
    asserter.next(V4_0);
    // @formatter:off
    asserter.simpleProperty(FormattedName.class).value("Simon Perreault").noMore();
    asserter.structuredName().family("Perreault").given("Simon").suffixes("ing. jr", "M.Sc.").noMore();
    asserter.dateProperty(Birthday.class).partialDate(PartialDate.builder().month(2).date(3).build()).noMore();
    asserter.dateProperty(Anniversary.class).partialDate(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).offset(new UtcOffset(false, -5, 0)).build()).noMore();
    asserter.property(Gender.class).expected(Gender.male()).noMore();
    asserter.simpleProperty(Language.class).value("fr").param("PREF", "1").next().value("en").param("PREF", "2").noMore();
    asserter.listProperty(Organization.class).values("Viagenie").param("TYPE", "work").noMore();
    asserter.address().streetAddress("2875 boul. Laurier, suite D2-630").locality("Quebec").region("QC").postalCode("G1V 2M2").country("Canada").label("Simon Perreault\n2875 boul. Laurier, suite D2-630\nQuebec, QC, Canada\nG1V 2M2").types(AddressType.WORK).noMore();
    asserter.telephone().uri(new TelUri.Builder("+1-418-656-9254").extension("102").build()).types(TelephoneType.WORK, TelephoneType.VOICE).next().uri(new TelUri.Builder("+1-418-262-6501").build()).types(TelephoneType.WORK, TelephoneType.TEXT, TelephoneType.VOICE, TelephoneType.CELL, TelephoneType.VIDEO).noMore();
    asserter.email().value("simon.perreault@viagenie.ca").types(EmailType.WORK).noMore();
    asserter.geo().latitude(46.766336).longitude(-71.28955).param("TYPE", "work").noMore();
    asserter.binaryProperty(Key.class).url("http://www.viagenie.ca/simon.perreault/simon.asc").param("TYPE", "work").noMore();
    asserter.timezone().text("America/Montreal").noMore();
    asserter.simpleProperty(Url.class).value("http://nomis80.org").param("TYPE", "home").noMore();
    // @formatter:on
    asserter.validate().run();
    asserter.done();
}
Also used : UtcOffset(ezvcard.util.UtcOffset) Organization(ezvcard.property.Organization) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Key(ezvcard.property.Key) Url(ezvcard.property.Url) Test(org.junit.Test)

Example 18 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class TimezoneTest method set_value.

@Test
public void set_value() {
    Timezone property = new Timezone((String) null);
    property.setOffset(new UtcOffset(true, 1, 0));
    assertEquals(new UtcOffset(true, 1, 0), property.getOffset());
    assertNull(property.getText());
    property.setText("text");
    assertEquals(new UtcOffset(true, 1, 0), property.getOffset());
    assertEquals("text", property.getText());
}
Also used : UtcOffset(ezvcard.util.UtcOffset) Test(org.junit.Test)

Example 19 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class TimezoneTest method toTimeZone_text_and_offset.

@Test
public void toTimeZone_text_and_offset() {
    Timezone t = new Timezone(new UtcOffset(false, -5, 30), "text");
    TimeZone actual = t.toTimeZone();
    assertEquals(-(5 * 1000 * 60 * 60 + 30 * 1000 * 60), actual.getRawOffset());
    assertEquals("text", actual.getID());
}
Also used : UtcOffset(ezvcard.util.UtcOffset) TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Test(org.junit.Test)

Example 20 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class TimezoneScribe method _dataType.

@Override
protected VCardDataType _dataType(Timezone property, VCardVersion version) {
    String text = property.getText();
    UtcOffset offset = property.getOffset();
    switch(version) {
        case V2_1:
            return VCardDataType.UTC_OFFSET;
        case V3_0:
            if (offset != null) {
                return VCardDataType.UTC_OFFSET;
            }
            if (text != null) {
                return VCardDataType.TEXT;
            }
            break;
        case V4_0:
            if (text != null) {
                return VCardDataType.TEXT;
            }
            if (offset != null) {
                return VCardDataType.UTC_OFFSET;
            }
            break;
    }
    return _defaultDataType(version);
}
Also used : UtcOffset(ezvcard.util.UtcOffset)

Aggregations

UtcOffset (ezvcard.util.UtcOffset)20 Test (org.junit.Test)13 Key (ezvcard.property.Key)8 VCard (ezvcard.VCard)7 TelUri (ezvcard.util.TelUri)7 Address (ezvcard.property.Address)6 StructuredName (ezvcard.property.StructuredName)6 Timezone (ezvcard.property.Timezone)6 Birthday (ezvcard.property.Birthday)5 Telephone (ezvcard.property.Telephone)5 VCardAsserter (ezvcard.property.asserter.VCardAsserter)5 Anniversary (ezvcard.property.Anniversary)4 Geo (ezvcard.property.Geo)4 Organization (ezvcard.property.Organization)4 Url (ezvcard.property.Url)4 Photo (ezvcard.property.Photo)3 SimpleTimeZone (java.util.SimpleTimeZone)3 TimeZone (java.util.TimeZone)3 Sound (ezvcard.property.Sound)2 FreeBusyUrl (ezvcard.property.FreeBusyUrl)1