Class SimpleDateFormat
- All Implemented Interfaces:
Serializable, Cloneable
SimpleDateFormat
(java.text.SimpleDateFormat → vaadinx.text.SimpleDateFormat).
Why this exists. The Swing idiom static final SimpleDateFormat F =
new SimpleDateFormat("yyyy-MM-dd") is safe on the desktop — one JVM, one user,
one EDT touches it — but breaks two ways on the server:
- Thread-safety.
format/parsemutate an internalCalendar; a static instance is now shared across users and across virtual threads, so concurrent calls corrupt each other. - Zone-correctness. A plain
new SimpleDateFormat(...)formats in the server JVM zone, not the user's browser zone — a silent day-off bug (server UTC, user UTC+13 → yesterday). It doesn't even throw; it's just quietly wrong.
How it stays correct while staying a drop-in. This class extends
SimpleDateFormat so it's assignable everywhere a JDK
DateFormat/Format is, but it holds no live formatting
state of its own. It keeps a session-independent configuration template
(a plain JDK SimpleDateFormat used only as a prototype, never to
format), and every format/parse operates on a per-session
backing cloned from that template and pinned to the browser's time zone.
The instance itself is therefore safe to share JVM-wide (as a static),
because all mutable state lives in the session, not on the instance.
Thread-safety contract. Formatting/parsing from a Vaadin UI thread
(or an EHelper.callSwing(Runnable) continuation) is fully thread-safe and
browser-zoned: the backing is reached only under the Vaadin session lock, which
serialises all such access. On a background thread (no VaadinSession) it
degrades to a per-call throwaway pinned to the server default zone — race-free
(thread-local) and never throwing, i.e. at least as safe as the original code
and using the exact zone the original static instance used on that same thread.
Configuration / freeze model. Construction and configuration
(applyPattern, setLenient, setTimeZone, …) with no
current session write the template — this is the static-initialiser
window and never throws or reads a zone. Configuration from a live UI thread is
applied to that session's backing only (session-local; no cross-user leak). The
template freezes on first use (first format/parse or first backing
build); after that, reconfiguring from a background thread throws
IllegalStateException — silently rewriting a shared formatter for every
user is corruption the original single-JVM app never risked, so it fails loud
rather than degrading.
The backing is zoned via TimeZone.getTimeZone(java.time.ZoneId) —
the same arithmetic the DatePicker-backed surrogates convert with, so a
picked date formats as the day picked in every year, pre-1900 included.
Emulator-only — no surrogate. Like Timer / SwingWorker
(D_timer_swingworker), SimpleDateFormat is not a Component and has no Vaadin peer; the
stage-3 rewrite drops it entirely for java.time / SHelper.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class DateFormat
DateFormat.Field -
Field Summary
Fields inherited from class DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.SimpleDateFormat(String pattern) Deprecated.SimpleDateFormat(String pattern, DateFormatSymbols formatSymbols) Deprecated.SimpleDateFormat(String pattern, Locale locale) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyLocalizedPattern(String pattern) Deprecated.voidapplyPattern(String pattern) Deprecated.clone()Deprecated.Returns an independent emulator: its own deep-cloned template, its own identity (hence its own session backings), and reset to unfrozen so the clone is freely reconfigurable.booleanDeprecated.Equality on the configuration prototype (the emulator's effective config).format(Date date, StringBuffer toAppendTo, FieldPosition pos) Deprecated.Deprecated.Deprecated.Deprecated.Deprecated.Deprecated.Deprecated.inthashCode()Deprecated.booleanDeprecated.parse(String text, ParsePosition pos) Deprecated.voidset2DigitYearStart(Date startDate) Deprecated.voidsetCalendar(Calendar newCalendar) Deprecated.voidsetDateFormatSymbols(DateFormatSymbols newFormatSymbols) Deprecated.voidsetLenient(boolean lenient) Deprecated.voidsetNumberFormat(NumberFormat newNumberFormat) Deprecated.voidsetTimeZone(TimeZone zone) Deprecated.Specialisedconfigure(Consumer): a no-session write also records that the zone is explicit, so backings stop defaulting to browser/server zone and honour what the migrator set.Deprecated.Deprecated.Methods inherited from class DateFormat
format, format, getAvailableLocales, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getTimeInstance, getTimeInstance, getTimeInstance, parse, parseObjectMethods inherited from class Format
format, parseObject
-
Constructor Details
-
SimpleDateFormat
public SimpleDateFormat()Deprecated. -
SimpleDateFormat
Deprecated. -
SimpleDateFormat
-
SimpleDateFormat
Deprecated.
-
-
Method Details
-
format
Deprecated.- Overrides:
formatin classSimpleDateFormat
-
parse
Deprecated.- Overrides:
parsein classSimpleDateFormat
-
formatToCharacterIterator
Deprecated.- Overrides:
formatToCharacterIteratorin classSimpleDateFormat
-
applyPattern
Deprecated.- Overrides:
applyPatternin classSimpleDateFormat
-
applyLocalizedPattern
Deprecated.- Overrides:
applyLocalizedPatternin classSimpleDateFormat
-
toPattern
-
toLocalizedPattern
Deprecated.- Overrides:
toLocalizedPatternin classSimpleDateFormat
-
setDateFormatSymbols
Deprecated.- Overrides:
setDateFormatSymbolsin classSimpleDateFormat
-
getDateFormatSymbols
Deprecated.- Overrides:
getDateFormatSymbolsin classSimpleDateFormat
-
set2DigitYearStart
Deprecated.- Overrides:
set2DigitYearStartin classSimpleDateFormat
-
get2DigitYearStart
Deprecated.- Overrides:
get2DigitYearStartin classSimpleDateFormat
-
setLenient
-
isLenient
-
setCalendar
Deprecated.- Overrides:
setCalendarin classDateFormat
-
getCalendar
-
setNumberFormat
Deprecated.- Overrides:
setNumberFormatin classDateFormat
-
getNumberFormat
-
getTimeZone
-
setTimeZone
Deprecated.Specialisedconfigure(Consumer): a no-session write also records that the zone is explicit, so backings stop defaulting to browser/server zone and honour what the migrator set.- Overrides:
setTimeZonein classDateFormat
-
clone
Deprecated.Returns an independent emulator: its own deep-cloned template, its own identity (hence its own session backings), and reset to unfrozen so the clone is freely reconfigurable.super.clone()shallow-copies thetemplatereference, so it is re-cloned explicitly.- Overrides:
clonein classSimpleDateFormat
-
equals
Deprecated.Equality on the configuration prototype (the emulator's effective config).- Overrides:
equalsin classSimpleDateFormat
-
hashCode
-
com.vaadin.swingbridge.surrogates.util.BrowserDateUtils.formatAsISODate/formatAsDateorDateTimeFormatterinstead, which are stateless.