List of usage examples for java.util TimeZone useDaylightTime
public abstract boolean useDaylightTime();
From source file:Main.java
public static void main(String args[]) { TimeZone tzone = TimeZone.getDefault(); // checking daylight time System.out.println("Using day light time :" + tzone.useDaylightTime()); }
From source file:Main.java
public static String getTimeZoneOffset() { TimeZone timezone = TimeZone.getDefault(); int i = timezone.getRawOffset() / 1000; int j;//from w ww . ja v a 2s. co m double d; Object aobj[]; if (timezone.useDaylightTime() && timezone.inDaylightTime(new java.sql.Date(System.currentTimeMillis()))) j = 1; else j = 0; d = (double) i / 3600D + (double) j; aobj = new Object[1]; aobj[0] = Double.valueOf(d); return String.format("%.2f", aobj); }
From source file:org.forgerock.openam.cts.TokenTestUtils.java
/** * Required to correctly account for all factors when dealing with TimeZones. * * @param zone Non null./* w w w. jav a 2 s . c om*/ * @return */ private static int getTotalTimeZoneOffset(TimeZone zone) { int r = zone.getRawOffset(); if (zone.useDaylightTime()) { r += zone.getDSTSavings(); } return r; }
From source file:at.newsagg.utils.ParserUtils.java
private static int localTimeDiff(TimeZone tz, Date date) { if (tz.inDaylightTime(date)) { int dstSavings = 0; if (tz.useDaylightTime()) { dstSavings = 3600000; // shortcut, JDK 1.4 allows cleaner impl }/*from w w w.j a v a 2 s.c o m*/ return tz.getRawOffset() + dstSavings; } return tz.getRawOffset(); }
From source file:org.sipfoundry.sipxconfig.device.DeviceTimeZone.java
public void setTimeZone(TimeZone tz) { String tzn = tz.getID();/*from w w w .j a va2 s . co m*/ m_useDaylight = tz.useDaylightTime(); m_offset = tz.getRawOffset() / (int) DateUtils.MILLIS_PER_MINUTE; m_dstSavings = tz.getDSTSavings() / (int) DateUtils.MILLIS_PER_MINUTE; // Until there is a setting for DST rule, it must be guessed here based on the timezone // name // // XCF-977 - Doing string compares on ID is not predicable! On my gentoo system, I get // US/Eastern but on a FC4 machine I get America/New_York. Both running java1.5.0.06 // We'll wait for XCF-874 to address this properly. Until then, do not break whatever // seems to work for some systems in Europe, but default everyone else to US. Otherwise // the default of zero is not very helpful // See also: http://en.wikipedia.org/wiki/List_of_zoneinfo_time_zones if (tzn.matches("^Europe/.*")) { setDstParameters(DST_EU); } else { setDstParameters(DST_US); } }
From source file:org.jspresso.framework.application.startup.remote.RemoteStartup.java
/** * Starts the remote application passing it the client locale. * * @param startCommand//from w w w. j a va2 s . com * the start command wrapping the various client start parameters. * @return the commands to be executed by the client peer on startup. */ public List<RemoteCommand> start(RemoteStartCommand startCommand) { try { Locale locale = LocaleUtils.toLocale(startCommand.getLanguage()); IFrontendController<RComponent, RIcon, RAction> controller = getFrontendController(); if (!dupSessionNotifiedOnce && isDupSessionDetectionEnabled() && controller != null && controller.isStarted()) { dupSessionNotifiedOnce = true; RemoteMessageCommand errorMessage = createErrorMessageCommand(); errorMessage.setMessage(controller.getTranslation("session.dup", new Object[] { controller.getI18nName(controller, locale) }, locale)); // Do not return the singleton list directly since subclasses might add commands to it. return new ArrayList<>(Collections.singleton((RemoteCommand) errorMessage)); } dupSessionNotifiedOnce = false; setStartupLocale(locale); TimeZone serverTimeZone = TimeZone.getDefault(); int currentOffset = serverTimeZone.getOffset(System.currentTimeMillis()); TimeZone clientTz = null; if (currentOffset == startCommand.getTimezoneOffset()) { clientTz = serverTimeZone; } else { String[] availableIds = TimeZone.getAvailableIDs(startCommand.getTimezoneOffset()); if (availableIds.length > 0) { for (int i = 0; i < availableIds.length && clientTz == null; i++) { TimeZone tz = TimeZone.getTimeZone(availableIds[i]); if (tz.useDaylightTime() == serverTimeZone.useDaylightTime()) { clientTz = tz; } } if (clientTz == null) { clientTz = TimeZone.getTimeZone(availableIds[0]); } } else { clientTz = TimeZone.getDefault(); } } setClientTimeZone(clientTz); start(); controller = getFrontendController(); if (startCommand.getVersion() != null && !isClientVersionCompatible(startCommand.getVersion())) { RemoteMessageCommand errorMessage = createErrorMessageCommand(); assert controller != null; errorMessage.setMessage(controller.getTranslation("incompatible.client.version", new Object[] { startCommand.getVersion(), Build.getJspressoVersion() }, locale)); // Do not return the singleton list directly since subclasses might add commands to it. return new ArrayList<>(Collections.singleton((RemoteCommand) errorMessage)); } try { return handleCommands(Collections.singletonList((RemoteCommand) startCommand)); } catch (Throwable ex) { if (controller != null) { controller.traceUnexpectedException(ex); } return Collections.emptyList(); } } catch (RuntimeException ex) { LOG.error("An unexpected error occurred while starting the server.", ex); RemoteMessageCommand errorMessage = createErrorMessageCommand(); errorMessage.setMessage( "An unexpected error occurred while starting the server. Please contact the application manager."); // Do not return the singleton list directly since subclasses might add commands to it. return new ArrayList<>(Collections.singleton((RemoteCommand) errorMessage)); } }
From source file:org.dpadgett.timer.WorldClockFragment.java
private void newClockDialog(final int position) { final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(context.getString(R.string.world_clock_select_timezone)); final Map<String, String> timezoneNameToId = new HashMap<String, String>(); final Set<Integer> timezones = new TreeSet<Integer>(); final Map<Integer, List<String>> offsetToName = new HashMap<Integer, List<String>>(); final long currentTime = System.currentTimeMillis(); for (final String timezone : TimeZone.getAvailableIDs()) { final TimeZone tz = TimeZone.getTimeZone(timezone); final boolean isDaylight = tz.useDaylightTime(); final String timezoneName = tz.getDisplayName(isDaylight, TimeZone.LONG, Locale.getDefault()); if (timezoneNameToId.containsKey(timezoneName)) { continue; }/*from www .j a va 2 s. co m*/ final int millisOffset = tz.getOffset(currentTime); timezones.add(millisOffset); if (!offsetToName.containsKey(millisOffset)) { offsetToName.put(millisOffset, new ArrayList<String>()); } offsetToName.get(millisOffset).add(timezoneName); timezoneNameToId.put(timezoneName, timezone); } for (final List<String> names : offsetToName.values()) { Collections.sort(names); } if (position > -1) { builder.setPositiveButton(context.getString(R.string.world_clock_button_remove), new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { clockList.remove(position); clocksListAdapter.notifyDataSetChanged(); final SharedPreferences.Editor prefs = context .getSharedPreferences("WorldClocks", Context.MODE_PRIVATE).edit(); prefs.putInt("numClocks", clockList.size()); int idx; for (idx = position; idx < clockList.size(); idx++) { prefs.putString("clock" + idx, clockList.get(idx)); } prefs.remove("clock" + idx); prefs.commit(); } }); } final LinearLayout tzView = (LinearLayout) LayoutInflater.from(context) .inflate(R.layout.timezone_picker_dialog, (ViewGroup) finder.findViewById(R.id.layout_root)); final List<String> initialItems = new ArrayList<String>(); initialItems.add(context.getString(R.string.world_clock_timezone_gmt)); initialItems.add(context.getString(R.string.world_clock_timezone_utc)); final ArrayAdapter<String> adapter = ArrayAdapter.newArrayAdapter(context, R.layout.timezone_dialog_list_item, initialItems); final ListView timezoneList = (ListView) tzView.findViewById(R.id.timezoneList); timezoneList.setAdapter(adapter); final TextView sliderView = (TextView) tzView.findViewById(R.id.timezoneLabel); final SeekBar timezoneSeeker = (SeekBar) tzView.findViewById(R.id.timezoneSeeker); final List<Integer> timezonesList = new ArrayList<Integer>(timezones); timezoneSeeker.setMax(timezonesList.size() - 1); if (position > -1) { final int offset = TimeZone.getTimeZone(clockList.get(position)).getOffset(currentTime); timezoneSeeker.setProgress(timezonesList.indexOf(offset)); } else { timezoneSeeker.setProgress(timezonesList.indexOf(0)); } timezoneSeeker.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { // initialize the timezoneSeeker { onProgressChanged(timezoneSeeker, timezoneSeeker.getProgress(), false); } @Override public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { adapter.clear(); adapter.addAll(offsetToName.get(timezonesList.get(progress))); final int millisOffset = timezonesList.get(progress); String offset = String.format("%02d:%02d", Math.abs(millisOffset / 1000 / 60 / 60), Math.abs(millisOffset / 1000 / 60) % 60); if (millisOffset / 1000 / 60 / 60 < 0) { offset = "-" + offset; } else { offset = "+" + offset; } sliderView.setText(context.getString(R.string.world_clock_timezone_label) + offset); } @Override public void onStartTrackingTouch(final SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { } }); builder.setView(tzView); final AlertDialog alert = builder.create(); timezoneList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int selectedPosition, final long id) { final String timezoneName = adapter.getItem(selectedPosition); final String timezone = timezoneNameToId.get(timezoneName); addNewClock(timezone, position); alert.dismiss(); } }); alert.show(); }
From source file:org.eclipse.gyrex.jobs.internal.commands.LsCmd.java
private void printSchedule(final ISchedule schedule) { final StrBuilder info = new StrBuilder(); info.append(schedule.getId());//from ww w . j av a2 s . c om if (!schedule.isEnabled()) { info.appendln(" DISABLED"); } final TimeZone timeZone = schedule.getTimeZone(); info.append(" time zone: ").append(timeZone.getDisplayName(false, TimeZone.LONG, Locale.US)) .appendln(timeZone.useDaylightTime() ? " (will adjust to daylight changes)" : " (independent of daylight changes)"); info.append(" queue: ").appendln(null != schedule.getQueueId() ? schedule.getQueueId() : "(default)"); String prefix = " entries: "; final List<IScheduleEntry> entries = schedule.getEntries(); if (!entries.isEmpty()) { for (final IScheduleEntry entry : entries) { info.append(prefix).append(entry.getId()).append(' ').append(entry.getCronExpression()).append(' ') .append(entry.getJobTypeId()).appendNewLine(); prefix = " "; final Map<String, String> parameter = entry.getJobParameter(); if (!parameter.isEmpty()) { final Set<Entry<String, String>> entrySet = parameter.entrySet(); for (final Entry<String, String> param : entrySet) { info.append(prefix).append(" ").append(param.getKey()).append('=') .appendln(param.getValue()); } } } } else { info.append(prefix).appendln("(none)"); } printf("%s", info.toString()); return; }
From source file:com.microsoft.exchange.DateHelpTest.java
@Test public void systemTimeZone() { List<String> availableIDs = Arrays.asList(TimeZone.getAvailableIDs()); assertFalse(CollectionUtils.isEmpty(availableIDs)); assertTrue(availableIDs.contains(TimeZones.UTC_ID)); assertTrue(availableIDs.contains("UTC")); TimeZone ical4jUTC = TimeZone.getTimeZone(TimeZones.UTC_ID); TimeZone sysUTC = TimeZone.getTimeZone("UTC"); assertEquals(ical4jUTC.getDSTSavings(), sysUTC.getDSTSavings()); assertEquals(ical4jUTC.getRawOffset(), sysUTC.getRawOffset()); assertTrue(ical4jUTC.hasSameRules(sysUTC)); TimeZone origDefaultTimeZone = TimeZone.getDefault(); assertNotNull(origDefaultTimeZone);/*from ww w.ja v a 2 s . c o m*/ assertEquals(TimeZone.getDefault().getRawOffset(), origDefaultTimeZone.getRawOffset()); log.info("TimeZone.DisplayName=" + origDefaultTimeZone.getDisplayName()); log.info("TimeZone.ID=" + origDefaultTimeZone.getID()); log.info("TimeZone.DSTSavings=" + origDefaultTimeZone.getDSTSavings()); log.info("TimeZone.RawOffset=" + origDefaultTimeZone.getRawOffset()); log.info("TimeZone.useDaylightTime=" + origDefaultTimeZone.useDaylightTime()); TimeZone.setDefault(ical4jUTC); assertEquals(ical4jUTC, TimeZone.getDefault()); log.info(" -- Defualt Time Zone has been changed successfully! -- "); TimeZone newDefaultTimeZone = TimeZone.getDefault(); log.info("TimeZone.DisplayName=" + newDefaultTimeZone.getDisplayName()); log.info("TimeZone.ID=" + newDefaultTimeZone.getID()); log.info("TimeZone.DSTSavings=" + newDefaultTimeZone.getDSTSavings()); log.info("TimeZone.RawOffset=" + newDefaultTimeZone.getRawOffset()); log.info("TimeZone.useDaylightTime=" + newDefaultTimeZone.useDaylightTime()); }
From source file:org.sleuthkit.autopsy.casemodule.Case.java
/** * Convert the Java timezone ID to the "formatted" string that can be * accepted by the C/C++ code. Example: "America/New_York" converted to * "EST5EDT", etc/*from w w w .ja v a 2 s. c om*/ * * @param timezoneID * * @return */ public static String convertTimeZone(String timezoneID) { TimeZone zone = TimeZone.getTimeZone(timezoneID); int offset = zone.getRawOffset() / 1000; int hour = offset / 3600; int min = (offset % 3600) / 60; DateFormat dfm = new SimpleDateFormat("z"); dfm.setTimeZone(zone); boolean hasDaylight = zone.useDaylightTime(); String first = dfm.format(new GregorianCalendar(2010, 1, 1).getTime()).substring(0, 3); // make it only 3 letters code String second = dfm.format(new GregorianCalendar(2011, 6, 6).getTime()).substring(0, 3); // make it only 3 letters code int mid = hour * -1; String result = first + Integer.toString(mid); if (min != 0) { result = result + ":" + Integer.toString(min); } if (hasDaylight) { result = result + second; } return result; }