Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20260627090323
20260705081251
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20260627090323
20260705081251
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
8 changes: 5 additions & 3 deletions sources/net.sf.j2s.java.core/src/java/text/DateFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,11 @@ public final static DateFormat getInstance() {
*/
public static Locale[] getAvailableLocales()
{
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(DateFormatProvider.class);
return pool.getAvailableLocales();
// SwingJS just return US locale
return new Locale[] { Locale.US };
// LocaleServiceProviderPool pool =
// LocaleServiceProviderPool.getPool(DateFormatProvider.class);
// return pool.getAvailableLocales();
}

/**
Expand Down
1 change: 1 addition & 0 deletions sources/net.sf.j2s.java.core/src/java/text/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public abstract class Format implements Serializable, Cloneable {

private static final long serialVersionUID = -299282585814624189L;
protected boolean isSimpleMMDDYY;
protected boolean isISO8601;



Expand Down
66 changes: 36 additions & 30 deletions sources/net.sf.j2s.java.core/src/java/text/SimpleDateFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ public SimpleDateFormat(String pattern, Locale locale, boolean allowNull) {
this.pattern = pattern;
this.locale = locale;
this.isSimpleMMDDYY = isSimple(pattern, locale);
this.isISO8601 = pattern.startsWith("yyyy-MM-dd'T'HH:mm:ss");
// lazy calendar initialization for SwingJS
// avoids loading 49 classes!
// this.formatData = DateFormatSymbols.getInstance(locale);
Expand All @@ -594,6 +595,8 @@ public SimpleDateFormat(String pattern, Locale locale, boolean allowNull) {

/* Initialize compiledPattern and numberFormat fields */
private void initializeLocale() {
if (this.isSimpleMMDDYY || this.isISO8601)
return;
if (locale == null)
locale = Locale.getDefault();
// Verify and compile the given pattern.
Expand Down Expand Up @@ -622,11 +625,10 @@ private static NumberFormat getCachedNumberFormatData(Locale key) {

@Override
public Calendar getCalendar() {
Calendar cal = super.getCalendar();
if (cal == null) {
if (super.getCalendar() == null) {
initializeCalendar();
}
return cal;
return calendar;
}

private void initializeCalendar() {
Expand Down Expand Up @@ -894,11 +896,11 @@ public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos
return format(date, toAppendTo, pos.getFieldDelegate());
}

@Override
public final String format (Object obj) {
return format(obj, new StringBuffer(), isSimpleMMDDYY ? null : new FieldPosition(0)).toString();
}
@Override
public final String format(Object obj) {
return format(obj, new StringBuffer(), isSimpleMMDDYY ? null : new FieldPosition(0)).toString();
}

@Override
public String format(Date date) {
if (isSimpleMMDDYY) {
Expand All @@ -923,8 +925,8 @@ private boolean isSimple(String pattern, Locale locale) {
switch (ch) {
case 'M':
case 'd':
case 'H': // H Hour in day (0-23)
case 'k': // k Hour in day (1-24)
case 'H': // H Hour in day (0-23)
case 'k': // k Hour in day (1-24)
case 'y':
case 'h':
case 'm':
Expand All @@ -940,27 +942,29 @@ private boolean isSimple(String pattern, Locale locale) {

// toISOString() returns a string in the
// 1970-01-01T00:00:00.000Z
// 0.........1.........
// 0.........1.........
// 01234567890123456789
//
//new Date().toString()
// new Date().toString()
// Sun Mar 09 14:35:53 GMT-0500 2025"
// 0.........1.........
// 0.........1.........
// 01234567890123456789
private final static String[] fields = { "yyyy", "yy", "MM", "M", "dd", "d", "hh", "h", "HH", "H", "kk", "k", "mm", "m", "ss", "s" };
private final static int[] fieldlens = { 4, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 };
private final static int[] fieldzero = { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
private final static int[] adj = { 0, 0, 3, 3, 0, 0, 12, 12, 23, 23, 24, 24, 0, 0, 0, 0 };
private final static int[] isopts = { 0, 2, 5, 5, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 };
private final static int[] isolens = { 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final static int[] locpts = { -4, -2, 4, 4, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 };
private final static int[] loclens = { 4, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final static String[] fields = { "yyyy", "yy", "MM", "M", "dd", "d", "hh", "h", "HH", "H", "kk", "k", "mm",
"m", "ss", "s" };
private final static int[] fieldlens = { 4, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 };
private final static int[] fieldzero = { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
private final static int[] adj = { 0, 0, 3, 3, 0, 0, 12, 12, 23, 23, 24, 24, 0, 0, 0, 0 };
private final static int[] isopts = { 0, 2, 5, 5, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 };
private final static int[] isolens = { 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final static int[] locpts = { -4, -2, 4, 4, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 };
private final static int[] loclens = { 4, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final static int fieldCount = fields.length;

private Object formatSimpleJS(Date date, StringBuffer sb) {
// considered doing this -- still could if we want GMT
//String iso = (/** @j2sNative date.toISOString() || */"");
String loc = (/** @j2sNative date.toString() || */"");
// String iso = (/** @j2sNative date.toISOString() || */"");
String loc = (/** @j2sNative date.toString() || */
"");
String ret = pattern;
for (int i = 0, l = 2; i < fieldCount; i++, l = 3 - l) {
int pt = ret.indexOf(fields[i]);
Expand All @@ -980,7 +984,7 @@ private String rep(String p, int pt, int flen, int fzero, String iso, int i0, in
String v = (i0 < 0 ? iso.substring(iso.length() + i0) : iso.substring(i0, i0 + isolen));
int iv = -1;
if (isoadj == 3) {
iv = (months.indexOf(v)/3 + 1);
iv = (months.indexOf(v) / 3 + 1);
} else if (isoadj != 0) {
iv = Integer.parseInt(v);
switch (isoadj) {
Expand Down Expand Up @@ -1085,17 +1089,19 @@ public AttributedCharacterIterator formatToCharacterIterator(Object obj) {

// Maps from DecimalFormatSymbols index to Field constant
private static Field[] PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID;

private static Field[] getPatternIndexFieldIDs() {
if (PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID == null) {
PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID = new Field[] { Field.ERA, Field.YEAR, Field.MONTH,
Field.DAY_OF_MONTH, Field.HOUR_OF_DAY1, Field.HOUR_OF_DAY0, Field.MINUTE, Field.SECOND, Field.MILLISECOND,
Field.DAY_OF_WEEK, Field.DAY_OF_YEAR, Field.DAY_OF_WEEK_IN_MONTH, Field.WEEK_OF_YEAR, Field.WEEK_OF_MONTH,
Field.AM_PM, Field.HOUR1, Field.HOUR0, Field.TIME_ZONE, Field.TIME_ZONE, };
Field.DAY_OF_MONTH, Field.HOUR_OF_DAY1, Field.HOUR_OF_DAY0, Field.MINUTE, Field.SECOND,
Field.MILLISECOND, Field.DAY_OF_WEEK, Field.DAY_OF_YEAR, Field.DAY_OF_WEEK_IN_MONTH,
Field.WEEK_OF_YEAR, Field.WEEK_OF_MONTH, Field.AM_PM, Field.HOUR1, Field.HOUR0, Field.TIME_ZONE,
Field.TIME_ZONE, };
}
return PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID;
return PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID;

}

/**
* Private member function that does the real date/time formatting.
*/
Expand Down
97 changes: 56 additions & 41 deletions sources/net.sf.j2s.java.core/src/java/time/Instant.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
//import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
Expand All @@ -92,6 +92,7 @@
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import java.util.Date;
import java.util.Objects;

/**
Expand Down Expand Up @@ -392,7 +393,9 @@ public static Instant from(TemporalAccessor temporal) {
* @throws DateTimeParseException if the text cannot be parsed
*/
public static Instant parse(final CharSequence text) {
return DateTimeFormatter.ISO_INSTANT.parse(text, Instant::from);
long l = /** j2sNative new Date(text.toString()).getTime() || */0;
return ofEpochMilli(l);
//DateTimeFormatter.ISO_INSTANT.parse(text, Instant::from);
}

//-----------------------------------------------------------------------
Expand Down Expand Up @@ -1321,45 +1324,57 @@ public int hashCode() {
*/
@Override
public String toString() {
return DateTimeFormatter.ISO_INSTANT.format(this);
}

// -----------------------------------------------------------------------
/**
* Writes the object using a
* <a href="../../serialized-form.html#java.time.Ser">dedicated serialized form</a>.
* @serialData
* <pre>
* out.writeByte(2); // identifies an Instant
* out.writeLong(seconds);
* out.writeInt(nanos);
* </pre>
*
* @return the instance of {@code Ser}, not null
*/
private Object writeReplace() {
return new Ser(Ser.INSTANT_TYPE, this);
}

/**
* Defend against malicious streams.
*
* @param s the stream to read
* @throws InvalidObjectException always
*/
private void readObject(ObjectInputStream s) throws InvalidObjectException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}

void writeExternal(DataOutput out) throws IOException {
out.writeLong(seconds);
out.writeInt(nanos);
}

static Instant readExternal(DataInput in) throws IOException {
long seconds = in.readLong();
int nanos = in.readInt();
return Instant.ofEpochSecond(seconds, nanos);
@SuppressWarnings("unused")
Date d = new Date(this.toEpochMilli());

/**
*
* @j2sNative
*
* return d.toISOString();
*/
{
return null;
// return DateTimeFormatter.ISO_INSTANT.format(this);
}
}

// // -----------------------------------------------------------------------
// /**
// * Writes the object using a
// * <a href="../../serialized-form.html#java.time.Ser">dedicated serialized form</a>.
// * @serialData
// * <pre>
// * out.writeByte(2); // identifies an Instant
// * out.writeLong(seconds);
// * out.writeInt(nanos);
// * </pre>
// *
// * @return the instance of {@code Ser}, not null
// */
// private Object writeReplace() {
// return new Ser(Ser.INSTANT_TYPE, this);
// }
//
// /**
// * Defend against malicious streams.
// *
// * @param s the stream to read
// * @throws InvalidObjectException always
// */
// private void readObject(ObjectInputStream s) throws InvalidObjectException {
// throw new InvalidObjectException("Deserialization via serialization delegate");
// }
//
// void writeExternal(DataOutput out) throws IOException {
// out.writeLong(seconds);
// out.writeInt(nanos);
// }
//
// static Instant readExternal(DataInput in) throws IOException {
// long seconds = in.readLong();
// int nanos = in.readInt();
// return Instant.ofEpochSecond(seconds, nanos);
// }
//
}
62 changes: 9 additions & 53 deletions sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;

import javajs.api.js.HTML5Applet.JSFunction;
import javajs.api.js.HTML5Applet;
import javajs.api.js.HTML5Applet.JSFunction;
import javajs.util.JSThread;
import javajs.util.PT;
import sun.awt.AppContext;
Expand Down Expand Up @@ -930,58 +930,14 @@ else if (family.equals("monospaced"))
* @param isoType null, 8824, or 8601, or a standard SimpleDataFormat format
* @return formatted date
*/
public static String getDateFormat(String isoType) {
String prefix = "";
String suffix = "";
/**
*
* Mon Jan 07 2013 19:54:39 GMT-0600
* or YYYYMMDDHHmmssOHH'mm'
*
* @j2sNative
*
* if (isoType == null) {
* return ("" + (new Date())).split(" (")[0];
* }
* if (isoType.indexOf("8824") >= 0) {
* var d = new Date();
* var x = d.toString().split(" ");
* var MM = "0" + (1 + d.getMonth()); MM = MM.substring(MM.length - 2);
* var dd = "0" + d.getDate(); dd = dd.substring(dd.length - 2);
* return x[3] + MM + dd + x[4].replace(/\:/g,"") + x[5].substring(3,6) + "'" + x[5].substring(6,8) + "'"
* }
* if (isoType.indexOf("8601") >= 0){
* var d = new Date();
* var x = d.toString().split(" ");
* // Firefox now doing this?
* if (x.length == 1)
* return x;
* var MM = "0" + (1 + d.getMonth()); MM = MM.substring(MM.length - 2);
* var dd = "0" + d.getDate(); dd = dd.substring(dd.length - 2);
* return x[3] + '-' + MM + '-' + dd + 'T' + x[4]
* }
*
*/
{
// if (isoType == null) {
// isoType = "EEE dd MMM yyyy HH:mm:ss 'GMT'Z";
// } else if (isoType.contains("8824")) {
// prefix = "D:";
// suffix = "'00'";
// isoType = "YYYYMMddHHmmssX";
// } else if (isoType.contains("8601")) {
// isoType = "yyyy-MM-dd'T'HH:mm:ss";
// }
Date date = (Date) Interface.getInstance("java.util.Date", true);
SimpleDateFormat format = (SimpleDateFormat) Interface.getInstanceWithParams("java.text.SimpleDateFormat", new Class<?>[] { String.class }, new Object[] { isoType});
return prefix + format.format(date) + suffix;
}
}

@Override
public void beep() {
System.out.println("JSToolkit.beep");
}
public static String getDateFormat(String isoType) {
return JSUtil.getDateFormat(isoType);
}

@Override
public void beep() {
System.out.println("JSToolkit.beep");
}

/**
* Get a gnu.jpdf.PDFJob.
Expand Down
Loading