Java Code Examples for org.joda.time.DateTimeZone#setDefault()

The following examples show how to use org.joda.time.DateTimeZone#setDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestISODateTimeFormatParsing.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void test_dateTimeNoMillis() {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis();
    assertParse(parser, "2006-02-04T10:20:30Z", new DateTime(2006, 2, 4, 10, 20, 30, 0));
    assertParse(parser, "2006-02-4T10:20:30Z", new DateTime(2006, 2, 4, 10, 20, 30, 0));
    assertParse(parser, "2006-2-04T10:20:30Z", new DateTime(2006, 2, 4, 10, 20, 30, 0));
    assertParse(parser, "2006-2-4T10:20:30Z", new DateTime(2006, 2, 4, 10, 20, 30, 0));
    assertParse(parser, "2006-02-04T5:6:7Z", new DateTime(2006, 2, 4, 5, 6, 7, 0));
    assertParse(parser, false, "2006-02-T10:20:30Z");
    assertParse(parser, false, "2006-12T10:20:30Z");
    assertParse(parser, false, "2006-1T10:20:30Z");
    assertParse(parser, false, "2006T10:20:30Z");
    assertParse(parser, false, "200T10:20:30Z");
    assertParse(parser, false, "20T10:20:30Z");
    assertParse(parser, false, "2T10:20:30Z");
    assertParse(parser, false, "2006-02-04T10:20Z");
    assertParse(parser, false, "2006-02-04T10:2Z");
    assertParse(parser, false, "2006-02-04T10Z");
    assertParse(parser, false, "2006-02-04T1Z");
}
 
Example 2
Source File: DatePartitionedNestedRetriever.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@Override
public void init(SourceState state) {
  DateTimeZone.setDefault(DateTimeZone
      .forID(state.getProp(ConfigurationKeys.SOURCE_TIMEZONE, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE)));

  initDatePartition(state);
  this.sourcePartitionPrefix =
      state.getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_PREFIX, StringUtils.EMPTY);

  this.sourcePartitionSuffix =
      state.getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_SUFFIX, StringUtils.EMPTY);
  this.sourceDir = new Path(state.getProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY));
  this.leadTimeDuration = PartitionAwareFileRetrieverUtils.getLeadTimeDurationFromConfig(state);
  this.helper = new HadoopFsHelper(state);
  this.schemaInSourceDir = state.getPropAsBoolean(ConfigurationKeys.SCHEMA_IN_SOURCE_DIR,
      ConfigurationKeys.DEFAULT_SCHEMA_IN_SOURCE_DIR);
  this.schemaFile = this.schemaInSourceDir ? state.getProp(ConfigurationKeys.SCHEMA_FILENAME,
      ConfigurationKeys.DEFAULT_SCHEMA_FILENAME) : "";
}
 
Example 3
Source File: TestISODateTimeFormatParsing.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void test_basicDateTimeNoMillis() {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTimeFormatter parser = ISODateTimeFormat.basicDateTimeNoMillis();
    assertParse(parser, "20061204T102030Z", new DateTime(2006, 12, 4, 10, 20, 30, 0));
    assertParse(parser, false, "2006120T102030Z");
    assertParse(parser, false, "200612T102030Z");
    assertParse(parser, false, "20061T102030Z");
    assertParse(parser, false, "2006T102030Z");
    assertParse(parser, false, "200T102030Z");
    assertParse(parser, false, "20T102030Z");
    assertParse(parser, false, "2T102030Z");
    assertParse(parser, false, "20061204T10203Z");
    assertParse(parser, false, "20061204T1020Z");
    assertParse(parser, false, "20061204T102Z");
    assertParse(parser, false, "20061204T10Z");
    assertParse(parser, false, "20061204T1Z");
}
 
Example 4
Source File: TestISODateTimeFormatParsing.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void test_dateTime() {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTimeFormatter parser = ISODateTimeFormat.dateTime();
    assertParse(parser, "2006-02-04T10:20:30.400999999Z", new DateTime(2006, 2, 4, 10, 20, 30, 400));
    assertParse(parser, "2006-02-04T10:20:30.400Z", new DateTime(2006, 2, 4, 10, 20, 30, 400));
    assertParse(parser, "2006-02-04T10:20:30.40Z", new DateTime(2006, 2, 4, 10, 20, 30, 400));
    assertParse(parser, "2006-02-04T10:20:30.4Z", new DateTime(2006, 2, 4, 10, 20, 30, 400));
    assertParse(parser, "2006-02-4T10:20:30.400Z", new DateTime(2006, 2, 4, 10, 20, 30, 400));
    assertParse(parser, "2006-2-04T10:20:30.400Z", new DateTime(2006, 2, 4, 10, 20, 30, 400));
    assertParse(parser, "2006-2-4T10:20:30.400Z", new DateTime(2006, 2, 4, 10, 20, 30, 400));
    assertParse(parser, "2006-02-04T5:6:7.800Z", new DateTime(2006, 2, 4, 5, 6, 7, 800));
    assertParse(parser, false, "2006-02-T10:20:30.400Z");
    assertParse(parser, false, "2006-12T10:20:30.400Z");
    assertParse(parser, false, "2006-1T10:20:30.400Z");
    assertParse(parser, false, "2006T10:20:30.400Z");
    assertParse(parser, false, "200T10:20:30.400Z");
    assertParse(parser, false, "20T10:20:30.400Z");
    assertParse(parser, false, "2T10:20:30.400Z");
    assertParse(parser, false, "2006-02-04T10:20.400Z");
    assertParse(parser, false, "2006-02-04T10:2.400Z");
    assertParse(parser, false, "2006-02-04T10.400Z");
    assertParse(parser, false, "2006-02-04T1.400Z");
}
 
Example 5
Source File: TestGregorianChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(originalDateTimeZone);
    TimeZone.setDefault(originalTimeZone);
    Locale.setDefault(originalLocale);
    originalDateTimeZone = null;
    originalTimeZone = null;
    originalLocale = null;
}
 
Example 6
Source File: TestNullConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(DateTimeZone.forID("Europe/London"));
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
    
    ISO = ISOChronology.getInstance();
    JULIAN = JulianChronology.getInstance();
}
 
Example 7
Source File: TestCopticChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
}
 
Example 8
Source File: TestISODateTimeFormatParsing.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_basicTTime() {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTimeFormatter parser = ISODateTimeFormat.basicTTime();
    assertParse(parser, "T102030.400999999Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, "T102030.400Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, "T102030.40Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, "T102030.4Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, false, "T10203.400Z");
    assertParse(parser, false, "T1020.400Z");
    assertParse(parser, false, "T102.400Z");
    assertParse(parser, false, "T10.400Z");
    assertParse(parser, false, "T1.400Z");
}
 
Example 9
Source File: TestISODateTimeFormatParsing.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_hourMinuteSecond() {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTimeFormatter parser = ISODateTimeFormat.hourMinuteSecond();
    assertParse(parser, "10:20:30", new DateTime(1970, 1, 1, 10, 20, 30, 0));
    assertParse(parser, "5:6:7", new DateTime(1970, 1, 1, 5, 6, 7, 0));
    assertParse(parser, false, "10:20:30.400999999");
    assertParse(parser, false, "10:20:30.400");
    assertParse(parser, false, "10:20:30.4");
    assertParse(parser, false, "10:20.400");
    assertParse(parser, false, "10:2.400");
    assertParse(parser, false, "10.400");
    assertParse(parser, false, "1.400");
}
 
Example 10
Source File: TestISODateTimeFormatParsing.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_basicTime() {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTimeFormatter parser = ISODateTimeFormat.basicTime();
    assertParse(parser, "102030.400999999Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, "102030.400Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, "102030.40Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, "102030.4Z", new DateTime(1970, 1, 1, 10, 20, 30, 400));
    assertParse(parser, false, "10203.400Z");
    assertParse(parser, false, "1020.400Z");
    assertParse(parser, false, "102.400Z");
    assertParse(parser, false, "10.400Z");
    assertParse(parser, false, "1.400Z");
}
 
Example 11
Source File: TestPeriodFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    originalDateTimeZone = DateTimeZone.getDefault();
    originalTimeZone = TimeZone.getDefault();
    originalLocale = Locale.getDefault();
    DateTimeZone.setDefault(LONDON);
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Locale.setDefault(Locale.UK);
    f = ISOPeriodFormat.standard();
}
 
Example 12
Source File: TimeZoneChangedReceiver.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, @NonNull Intent intent) {
    String tzId = intent.getStringExtra("time-zone");

    try {
        DateTimeZone newDefault = DateTimeZone.forTimeZone(TimeZone.getDefault());
        DateTimeZone.setDefault(newDefault);
        Log.d("prayer-times-android", "TIMEZONE_CHANGED received, changed default timezone to \"" + tzId + "\"");
    } catch (IllegalArgumentException e) {
        Log.d("prayer-times-android", "Could not recognize timezone id \"" + tzId + "\"", e);
    }
}
 
Example 13
Source File: TestBuddhistChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(originalDateTimeZone);
    TimeZone.setDefault(originalTimeZone);
    Locale.setDefault(originalLocale);
    originalDateTimeZone = null;
    originalTimeZone = null;
    originalLocale = null;
}
 
Example 14
Source File: TestISODateTimeFormatParsing.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_timeNoMillis() {
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTimeFormatter parser = ISODateTimeFormat.timeNoMillis();
    assertParse(parser, "10:20:30Z", new DateTime(1970, 1, 1, 10, 20, 30, 0));
    assertParse(parser, "5:6:7Z", new DateTime(1970, 1, 1, 5, 6, 7, 0));
    assertParse(parser, false, "10:20Z");
    assertParse(parser, false, "10:2Z");
    assertParse(parser, false, "10Z");
    assertParse(parser, false, "1Z");
}
 
Example 15
Source File: TestNewDateFunctions.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void testCastTimestampToDate() throws Exception {
  String[] tzs = {"America/Los_Angeles", "UTC", "Europe/Paris", "Pacific/Auckland", "Australia/Melbourne"};
  for (String tz : tzs) {
    DateTimeZone.setDefault(DateTimeZone.forID(tz));
    testBuilder()
      .sqlQuery("SELECT CAST(\"datetime0\" AS DATE) res1 FROM (VALUES({ts '2016-01-02 00:46:36'})) tbl(datetime0)")
      .ordered()
      .baselineColumns("res1")
      .baselineValues(new LocalDateTime(2016, 1, 2, 0, 0))
      .go();
  }
}
 
Example 16
Source File: TestISOPeriodFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(originalDateTimeZone);
    TimeZone.setDefault(originalTimeZone);
    Locale.setDefault(originalLocale);
    originalDateTimeZone = null;
    originalTimeZone = null;
    originalLocale = null;
}
 
Example 17
Source File: TestConvertDateTime.java    From spork with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    currentDTZ = DateTimeZone.getDefault();

    // set the timezone to somethere other than UTC
    defaultDTZ = DateTimeZone.forID("+08:00");
    DateTimeZone.setDefault(defaultDTZ);
}
 
Example 18
Source File: EscrowTaskRunnerTest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
  DateTimeZone.setDefault(previousDateTimeZone);
}
 
Example 19
Source File: TestDefaultDateTimeZone.java    From spork with Apache License 2.0 4 votes vote down vote up
public void testTimeZone() throws IOException {
    // Usually set through "pig.datetime.default.tz"
    String defaultDTZ = "+03:00";
    DateTimeZone.setDefault(DateTimeZone.forID(defaultDTZ));
    String[] inputs = {
            "1970-01-01T00:00:00.000-08:00",
            "1970-01-01T00:00",
            "1970-01-01T00",
            "1970-01-01T",
            "1970-01T",
            "1970T",
            "1970-01-01T00:00-08:00",
            "1970-01-01T00-05:00",
            "1970-01-01T-08:00",
            "1970-01T-08:00",
            //"1970T+8:00", //Invalid format
            "1970-01-01",
            "1970-01",
            "1970",
    };
    String[] expectedDTZOutputs = {
            "-08:00",
            defaultDTZ,
            defaultDTZ,
            defaultDTZ,
            defaultDTZ,
            defaultDTZ,
            "-08:00",
            "-05:00",
            "-08:00",
            "-08:00",
            defaultDTZ,
            defaultDTZ,
            defaultDTZ
    };
    String[] expectedDTOutputs = {
            "1970-01-01T00:00:00.000-08:00",
            "1970-01-01T00:00:00.000" + defaultDTZ,
            "1970-01-01T00:00:00.000" + defaultDTZ,
            "1970-01-01T00:00:00.000" + defaultDTZ,
            "1970-01-01T00:00:00.000" + defaultDTZ,
            "1970-01-01T00:00:00.000" + defaultDTZ,
            "1970-01-01T00:00:00.000-08:00",
            "1970-01-01T00:00:00.000-05:00",
            "1970-01-01T00:00:00.000-08:00",
            "1970-01-01T00:00:00.000-08:00",
            "1970-01-01T00:00:00.000" + defaultDTZ,
            "1970-01-01T00:00:00.000" + defaultDTZ,
            "1970-01-01T00:00:00.000" + defaultDTZ
    };

    for( int i = 0; i < inputs.length; i++ ) {
        DateTimeZone dtz = ToDate.extractDateTimeZone( inputs[i] );
        assertEquals( expectedDTZOutputs[i], dtz.toString() );
        DateTime dt = ToDate.extractDateTime( inputs[i] );
        assertEquals( expectedDTOutputs[i], dt.toString() );
        System.out.println( "\"" + dt + "\"," );
    }

}
 
Example 20
Source File: TestTextFields.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
protected void tearDown() throws Exception {
    DateTimeZone.setDefault(originalDateTimeZone);
    Locale.setDefault(originalLocale);
    originalDateTimeZone = null;
    originalLocale = null;
}