Tabnine Logo
FastTimeZone
Code IndexAdd Tabnine to your IDE (free)

How to use
FastTimeZone
in
org.apache.commons.lang3.time

Best Java code snippets using org.apache.commons.lang3.time.FastTimeZone (Showing top 20 results out of 315)

origin: org.apache.commons/commons-lang3

/**
 * {@inheritDoc}
 */
@Override
void setCalendar(final FastDateParser parser, final Calendar cal, final String value) {
  cal.setTimeZone(FastTimeZone.getGmtTimeZone(value));
}
origin: org.apache.commons/commons-lang3

/**
 * Gets a TimeZone with GMT offsets.  A GMT offset must be either 'Z', or 'UTC', or match
 * <em>(GMT)? hh?(:?mm?)?</em>, where h and m are digits representing hours and minutes.
 *
 * @param pattern The GMT offset
 * @return A TimeZone with offset from GMT or null, if pattern does not match.
 */
public static TimeZone getGmtTimeZone(final String pattern) {
  if ("Z".equals(pattern) || "UTC".equals(pattern)) {
    return GREENWICH;
  }
  final Matcher m = GMT_PATTERN.matcher(pattern);
  if (m.matches()) {
    final int hours = parseInt(m.group(2));
    final int minutes = parseInt(m.group(4));
    if (hours == 0 && minutes == 0) {
      return GREENWICH;
    }
    return new GmtTimeZone(parseSign(m.group(1)), hours, minutes);
  }
  return null;
}
origin: org.apache.commons/commons-lang3

@Test
public void testZeroOffsetsReturnSingleton() {
  assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("+0"));
  assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("-0"));
}
origin: org.apache.commons/commons-lang3

@Test
public void testOlson() {
  assertEquals(TimeZone.getTimeZone("America/New_York"), FastTimeZone.getTimeZone("America/New_York"));
}
origin: org.apache.commons/commons-lang3

/**
 * Gets a TimeZone, looking first for GMT custom ids, then falling back to Olson ids.
 * A GMT custom id can be 'Z', or 'UTC', or has an optional prefix of GMT,
 * followed by sign, hours digit(s), optional colon(':'), and optional minutes digits.
 * i.e. <em>[GMT] (+|-) Hours [[:] Minutes]</em>
 *
 * @param id A GMT custom id (or Olson id
 * @return A timezone
 */
public static TimeZone getTimeZone(final String id) {
  final TimeZone tz = getGmtTimeZone(id);
  if (tz != null) {
    return tz;
  }
  return TimeZone.getTimeZone(id);
}
origin: de.knightsoft-net/gwt-commons-lang3

/**
 * Gets a TimeZone with GMT offsets.  A GMT offset must be either 'Z', or 'UTC', or match
 * <em>(GMT)? hh?(:?mm?)?</em>, where h and m are digits representing hours and minutes.
 *
 * @param pattern The GMT offset
 * @return A TimeZone with offset from GMT or null, if pattern does not match.
 */
public static TimeZone getGmtTimeZone(final String pattern) {
  if ("Z".equals(pattern) || "UTC".equals(pattern)) {
    return GREENWICH;
  }
  final Matcher m = GMT_PATTERN.matcher(pattern);
  if (m.matches()) {
    final int hours = parseInt(m.group(2));
    final int minutes = parseInt(m.group(4));
    if (hours == 0 && minutes == 0) {
      return GREENWICH;
    }
    return new GmtTimeZone(parseSign(m.group(1)), hours, minutes);
  }
  return null;
}
origin: org.apache.commons/commons-lang3

@Test
public void testUTC() {
  assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("UTC"));
}
origin: org.apache.commons/commons-lang3

  /**
   * {@inheritDoc}
   */
  @Override
  void setCalendar(final FastDateParser parser, final Calendar cal, final String timeZone) {
    final TimeZone tz = FastTimeZone.getGmtTimeZone(timeZone);
    if (tz != null) {
      cal.setTimeZone(tz);
    } else {
      final String lowerCase = timeZone.toLowerCase(locale);
      TzInfo tzInfo = tzNames.get(lowerCase);
      if (tzInfo == null) {
        // match missing the optional trailing period
        tzInfo = tzNames.get(lowerCase + '.');
      }
      cal.set(Calendar.DST_OFFSET, tzInfo.dstOffset);
      cal.set(Calendar.ZONE_OFFSET, tzInfo.zone.getRawOffset());
    }
  }
}
origin: io.virtdata/virtdata-lib-curves4

/**
 * Gets a TimeZone with GMT offsets.  A GMT offset must be either 'Z', or 'UTC', or match
 * <em>(GMT)? hh?(:?mm?)?</em>, where h and m are digits representing hours and minutes.
 *
 * @param pattern The GMT offset
 * @return A TimeZone with offset from GMT or null, if pattern does not match.
 */
public static TimeZone getGmtTimeZone(final String pattern) {
  if ("Z".equals(pattern) || "UTC".equals(pattern)) {
    return GREENWICH;
  }
  final Matcher m = GMT_PATTERN.matcher(pattern);
  if (m.matches()) {
    final int hours = parseInt(m.group(2));
    final int minutes = parseInt(m.group(4));
    if (hours == 0 && minutes == 0) {
      return GREENWICH;
    }
    return new GmtTimeZone(parseSign(m.group(1)), hours, minutes);
  }
  return null;
}
origin: org.apache.commons/commons-lang3

@Test
public void testBareGmt() {
  assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("GMT"));
}
origin: org.apache.commons/commons-lang3

@Test
public void testHoursColonMinutes() {
  assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("23:00").getRawOffset());
  assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("2:00").getRawOffset());
  assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("00:59").getRawOffset());
  assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("00:5").getRawOffset());
  assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("23:59").getRawOffset());
  assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("2:5").getRawOffset());
}
origin: io.virtdata/virtdata-lib-realer

/**
 * Gets a TimeZone with GMT offsets.  A GMT offset must be either 'Z', or 'UTC', or match
 * <em>(GMT)? hh?(:?mm?)?</em>, where h and m are digits representing hours and minutes.
 *
 * @param pattern The GMT offset
 * @return A TimeZone with offset from GMT or null, if pattern does not match.
 */
public static TimeZone getGmtTimeZone(final String pattern) {
  if ("Z".equals(pattern) || "UTC".equals(pattern)) {
    return GREENWICH;
  }
  final Matcher m = GMT_PATTERN.matcher(pattern);
  if (m.matches()) {
    final int hours = parseInt(m.group(2));
    final int minutes = parseInt(m.group(4));
    if (hours == 0 && minutes == 0) {
      return GREENWICH;
    }
    return new GmtTimeZone(parseSign(m.group(1)), hours, minutes);
  }
  return null;
}
origin: org.apache.commons/commons-lang3

@Test
public void testZ() {
  assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("Z"));
}
origin: org.apache.commons/commons-lang3

@Test
public void testHoursMinutes() {
  assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("2300").getRawOffset());
  assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("0200").getRawOffset());
  assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("0059").getRawOffset());
  assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("0005").getRawOffset());
  assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("2359").getRawOffset());
  assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("0205").getRawOffset());
}
origin: org.apache.commons/commons-lang3

@Test
public void testSign() {
  assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("+23:00").getRawOffset());
  assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("+2:00").getRawOffset());
  assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("-23:00").getRawOffset());
  assertEquals(-HOURS_2, FastTimeZone.getGmtTimeZone("-2:00").getRawOffset());
}
origin: org.apache.commons/commons-lang3

@Test
public void testGmtPrefix() {
  assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("GMT+23:00").getRawOffset());
  assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("GMT-23:00").getRawOffset());
}
origin: org.apache.commons/commons-lang3

@BeforeClass
public static void classSetUp() {
  DEFAULT_LOCALE_BEFORE_TEST = Locale.getDefault();
  if (!DEFAULT_LOCALE_BEFORE_TEST.equals(Locale.CANADA)) {
    Locale.setDefault(Locale.CANADA);
  } else {
    // you seem to be from Canada...
    Locale.setDefault(Locale.CHINESE);
  }
  TEST_DEFAULT_LOCALE = Locale.getDefault();
  DEFAULT_TIMEZONE_BEFORE_TEST = TimeZone.getDefault();
  final TimeZone utc = FastTimeZone.getGmtTimeZone();
  if (!DEFAULT_TIMEZONE_BEFORE_TEST.equals(utc)) {
    TimeZone.setDefault(utc);
  } else {
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
  }
  TEST_DEFAULT_TIMEZONE = TimeZone.getDefault();
}
origin: org.apache.commons/commons-lang3

@Test
public void testGetGmtTimeZone() {
  assertEquals(0, FastTimeZone.getGmtTimeZone().getRawOffset());
}
origin: org.apache.commons/commons-lang3

private void testUTC(final String expectedValue, final String pattern) {
  final TimeZone timeZone = FastTimeZone.getGmtTimeZone();
  assertFormats(expectedValue, pattern, timeZone, createFebruaryTestDate(timeZone));
}
origin: org.apache.commons/commons-lang3

@Test
public void testFormat() {
  final Calendar c = Calendar.getInstance(FastTimeZone.getGmtTimeZone());
  c.set(2005, Calendar.JANUARY, 1, 12, 0, 0);
  c.setTimeZone(TimeZone.getDefault());
  final StringBuilder buffer = new StringBuilder ();
  final int year = c.get(Calendar.YEAR);
  final int month = c.get(Calendar.MONTH) + 1;
  final int day = c.get(Calendar.DAY_OF_MONTH);
  final int hour = c.get(Calendar.HOUR_OF_DAY);
  buffer.append (year);
  buffer.append(month);
  buffer.append(day);
  buffer.append(hour);
  assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH"));
  assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH"));
  assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US));
  assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH", Locale.US));
}
org.apache.commons.lang3.timeFastTimeZone

Javadoc

Faster methods to produce custom time zones.

Most used methods

  • getGmtTimeZone
    Gets a TimeZone with GMT offsets. A GMT offset must be either 'Z', or 'UTC', or match(GMT)? hh?(:?mm
  • parseInt
  • parseSign
  • getTimeZone
    Gets a TimeZone, looking first for GMT custom ids, then falling back to Olson ids. A GMT custom id c

Popular in Java

  • Creating JSON documents from java classes using gson
  • startActivity (Activity)
  • setScale (BigDecimal)
  • getApplicationContext (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now