Skip to content

Commit

Permalink
fix Convert Date
Browse files Browse the repository at this point in the history
  • Loading branch information
isayan committed May 26, 2022
1 parent 4e265e5 commit 8a49ef9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 44 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
netbeans.org-netbeans-modules-javascript2-requirejs.enabled=true
release_version_major=2.2
release_version_minor=13.1
release_version_minor=13.2
Binary file not shown.
Binary file modified release/YaguraExtender-v2.2.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions src/main/java/yagura/view/JTransCoderTab.form
Original file line number Diff line number Diff line change
Expand Up @@ -2449,9 +2449,9 @@
<Component id="btnZoneDateCopy" min="-2" pref="90" max="-2" attributes="0"/>
<Component id="btnJavaSerialCopy" alignment="0" min="-2" pref="90" max="-2" attributes="0"/>
<Component id="btnExcelSerial" min="-2" pref="90" max="-2" attributes="0"/>
<Component id="cmbTimezone" min="-2" pref="153" max="-2" attributes="0"/>
<Component id="cmbTimezone" min="-2" pref="261" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="824" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="716" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -2580,7 +2580,7 @@
<Component class="javax.swing.JFormattedTextField" name="txtExcelSerial">
<Properties>
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.editors.AbstractFormatterFactoryEditor">
<Format format="####.00" subtype="-1" type="0"/>
<Format format="####.000000" subtype="-1" type="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="11"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
Expand Down
51 changes: 26 additions & 25 deletions src/main/java/yagura/view/JTransCoderTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ public class JTransCoderTab extends javax.swing.JPanel implements ITab {
final PropertyChangeListener listener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
ThemeUI.changeStyleTheme(txtOutputRaw);
ThemeUI.changeStyleTheme(txtOutputFormat);
ThemeUI.changeStyleTheme(txtOutputRaw);
ThemeUI.changeStyleTheme(txtOutputFormat);
}
};

/**
* Creates new form JTransCoder
*/
public JTransCoderTab() {
initComponents();
customizeComponents();
this.listener.propertyChange(null);
UIManager.addPropertyChangeListener(this.listener);
UIManager.addPropertyChangeListener(this.listener);
}
private final QuickSearchTab quickSearchTabRaw = new QuickSearchTab();
private final QuickSearchTab quickSearchTabFormat = new QuickSearchTab();
Expand Down Expand Up @@ -115,15 +115,15 @@ public JTransCoderTab() {
private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea txtOutputFormat;

private final static DateTimeFormatter GMT_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd H:mm:ss zzz");

private final static String [] SHORT_ZONEIDS = {
"ACT", "AET", "AGT", "ART", "AST", "BET", "BST", "CAT", "CNT", "CST", "CTT", "EAT", "ECT", "IET", "IST", "JST", "MIT", "NET", "NST", "PLT", "PNT", "PRT", "PST", "SST", "VST", "EST", "MST", "HST"
"GMT", "ACT", "AET", "AGT", "ART", "AST", "BET", "BST", "CAT", "CNT", "CST", "CTT", "EAT", "ECT", "IET", "IST", "JST", "MIT", "NET", "NST", "PLT", "PNT", "PRT", "PST", "SST", "VST", "EST", "MST", "HST"
};

private final ViewStateDecoderTab viewStateDecoderTab = new ViewStateDecoderTab();

private final JWTTokenDecoderTab jwtTokenDecoderTab = new JWTTokenDecoderTab();

private void customizeComponents() {

/**
Expand Down Expand Up @@ -217,12 +217,14 @@ public void setData(byte[] rawData) {
* * UI design end **
*/


int tz_offset = 0;
ZoneId systemZone = ZoneId.systemDefault();
for (int i = 0; i < SHORT_ZONEIDS.length; i++) {
ZoneId zone = ZoneId.of(ZoneId.SHORT_IDS.get(SHORT_ZONEIDS[i]));
this.cmbTimezone.addItem(SHORT_ZONEIDS[i] + " - " + zone.getId());
if (systemZone.equals(zone)) {
ZoneId zoneId = ZoneId.of(SHORT_ZONEIDS[i], ZoneId.SHORT_IDS);
String shortIDS = "GMT".equals(SHORT_ZONEIDS[i]) ? "Greenwich Mean Time" : ZoneId.SHORT_IDS.get(SHORT_ZONEIDS[i]);
this.cmbTimezone.addItem(SHORT_ZONEIDS[i] + " - " + shortIDS + " (" + zoneId.getRules().getOffset(Instant.EPOCH) + ")");
if (systemZone.equals(zoneId)) {
tz_offset = i;
}
}
Expand Down Expand Up @@ -280,7 +282,7 @@ private void txtOutputRawCaretUpdate(javax.swing.event.CaretEvent evt) {
private ZoneId getSelectZoneId() {
int index = this.cmbTimezone.getSelectedIndex();
if (0 <= index && index < SHORT_ZONEIDS.length) {
return ZoneId.of(ZoneId.SHORT_IDS.get(SHORT_ZONEIDS[index]));
return ZoneId.of(SHORT_ZONEIDS[index], ZoneId.SHORT_IDS);
}
else {
return ZoneId.systemDefault();
Expand Down Expand Up @@ -2065,7 +2067,7 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
}
});

txtExcelSerial.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("####.00"))));
txtExcelSerial.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("####.000000"))));
txtExcelSerial.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
txtExcelSerial.setToolTipText("");
txtExcelSerial.setMinimumSize(new java.awt.Dimension(180, 22));
Expand Down Expand Up @@ -2140,8 +2142,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(btnZoneDateCopy, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnJavaSerialCopy, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnExcelSerial, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbTimezone, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(824, 824, 824))
.addComponent(cmbTimezone, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(716, 716, 716))
);
tabDateConverterLayout.setVerticalGroup(
tabDateConverterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand Down Expand Up @@ -2481,7 +2483,7 @@ private void btnEncodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
}
}
encode = buff.toString();
} else if (this.rdoCLang.isSelected()) {
} else if (this.rdoCLang.isSelected()) {
encode = TransUtil.encodeCLangQuote(encode, metaChar);
} else if (this.rdoSQLLang.isSelected()) {
encode = TransUtil.encodeSQLLangQuote(encode, metaChar);
Expand Down Expand Up @@ -3178,7 +3180,6 @@ private void spnDatetimeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-F
private void cmbTimezoneItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbTimezoneItemStateChanged
Date date = this.getConverterDateTime();
ZoneId zoneId = getSelectZoneId();
BurpExtender.errPrintln("ZoneId:" + zoneId);
ZonedDateTime zdtm = ZonedDateTime.ofInstant(date.toInstant(), zoneId);
this.txtZoneDate.setText(GMT_DATE_FORMATTER.format(zdtm));
}//GEN-LAST:event_cmbTimezoneItemStateChanged
Expand Down Expand Up @@ -3216,27 +3217,27 @@ private void btnHexIPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
}//GEN-LAST:event_btnHexIPActionPerformed

private void btnDecIPConvertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDecIPConvertActionPerformed
int dec1 = ConvertUtil.parseIntDefault(this.txtDec1.getText(), -1);
int dec2 = ConvertUtil.parseIntDefault(this.txtDec2.getText(), -1);
int dec3 = ConvertUtil.parseIntDefault(this.txtDec3.getText(), -1);
int dec1 = ConvertUtil.parseIntDefault(this.txtDec1.getText(), -1);
int dec2 = ConvertUtil.parseIntDefault(this.txtDec2.getText(), -1);
int dec3 = ConvertUtil.parseIntDefault(this.txtDec3.getText(), -1);
int dec4 = ConvertUtil.parseIntDefault(this.txtDec4.getText(), -1);
if (dec1 < 0 || dec2 < 0 || dec3 < 0 || dec4 < 0 ) {
this.lblIPValid.setText("IP addres Invalid");
return;
}
if (!(0 <= dec1 && dec1 <= 255 &&
0 <= dec2 && dec2 <= 255 &&
0 <= dec3 && dec3 <= 255 &&
if (!(0 <= dec1 && dec1 <= 255 &&
0 <= dec2 && dec2 <= 255 &&
0 <= dec3 && dec3 <= 255 &&
0 <= dec4 && dec4 <= 255)) {
this.lblIPValid.setText("IP addres renge Invalid");
return;
}

this.txtDotOctIP.setText(IpUtil.ipv4ToDotOct(dec1, dec2, dec3, dec4));
this.txtOctIP.setText(IpUtil.ipv4ToOct(dec1, dec2, dec3, dec4));
this.txtHexIP.setText(IpUtil.ipv4ToHex(dec1, dec2, dec3, dec4));
this.txtDotHexIP.setText(IpUtil.ipv4ToDotHex(dec1, dec2, dec3, dec4));
this.txtIntIP.setText(IpUtil.ipv4ToInt(dec1, dec2, dec3, dec4));
this.txtDotHexIP.setText(IpUtil.ipv4ToDotHex(dec1, dec2, dec3, dec4));
this.txtIntIP.setText(IpUtil.ipv4ToInt(dec1, dec2, dec3, dec4));
}//GEN-LAST:event_btnDecIPConvertActionPerformed

private void txtUnixtimeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtUnixtimeFocusLost
Expand Down
40 changes: 25 additions & 15 deletions src/test/java/extend/util/external/TransUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
Expand Down Expand Up @@ -660,7 +661,7 @@ public void testStandardLangMeta() {
assertEquals("a\\tb\\rc\\nd", TransUtil.encodeStandardLangMeta("a\tb\rc\nd"));
assertEquals("a\\\\d", TransUtil.encodeStandardLangMeta("a\\\\d"));
}

/**
* Test of encodeJsLangMeta,decodeJsLangMeta method, of class TransUtil.
*/
Expand Down Expand Up @@ -718,7 +719,7 @@ public void testCLangQuote() {
assertEquals("host", TransUtil.decodeCLangQuote("host", false));
assertEquals("\\123\"456\\", TransUtil.decodeCLangQuote("\\\\123\\\"456\\\\", false));
assertEquals("\\123'456\\", TransUtil.decodeCLangQuote("\\\\123'456\\\\", false));

// metachar
assertEquals("\\r\\nhost\\t", TransUtil.encodeCLangQuote("\r\nhost\t", true));
assertEquals("ho\\\\st", TransUtil.encodeCLangQuote("ho\\st", true));
Expand All @@ -728,7 +729,7 @@ public void testCLangQuote() {
assertEquals("\r\nhost\t", TransUtil.decodeCLangQuote("\\r\\nhost\\t", true));
assertEquals("ho\\st", TransUtil.decodeCLangQuote("ho\\\\st", true));
assertEquals("\\123\"456\\", TransUtil.decodeCLangQuote("\\\\123\\\"456\\\\", true));
assertEquals("\\123'456\\", TransUtil.decodeCLangQuote("\\\\123'456\\\\", true));
assertEquals("\\123'456\\", TransUtil.decodeCLangQuote("\\\\123'456\\\\", true));
}

/**
Expand All @@ -745,12 +746,12 @@ public void testSQLLangQuote() {
// metachar
assertEquals("\\r\\nhost\\t", TransUtil.encodeSQLLangQuote("\r\nhost\t", true));
assertEquals("ho\\st", TransUtil.encodeSQLLangQuote("ho\\st", true));
assertEquals("\\\\123'456\\\\", TransUtil.decodeSQLangQuote("\\\\123''456\\\\", true));
assertEquals("\\\\123'456\\\\", TransUtil.decodeSQLangQuote("\\\\123''456\\\\", true));
assertEquals("\\123\"456\\", TransUtil.encodeSQLLangQuote("\\123\"456\\", true));

assertEquals("\r\nhost\t", TransUtil.decodeSQLangQuote("\\r\\nhost\\t", true));
assertEquals("ho\\st", TransUtil.decodeSQLangQuote("ho\\st", true));
assertEquals("\\\\123'456\\\\", TransUtil.decodeSQLangQuote("\\\\123''456\\\\", true));
assertEquals("\\\\123'456\\\\", TransUtil.decodeSQLangQuote("\\\\123''456\\\\", true));
assertEquals("\\123\"456\\", TransUtil.decodeSQLangQuote("\\123\"456\\", true));
}

Expand Down Expand Up @@ -957,32 +958,32 @@ public void testStringBuilder() {
b.append((String)null);
System.out.println("append:" + b.toString());
}

@Test
public void testOrderdChar() {
{
char ord = TransUtil.getOrderdChar(0);
assertEquals(ord, '0');
assertEquals(ord, '0');
}
{
char ord = TransUtil.getOrderdChar(10);
assertEquals(ord, 'A');
assertEquals(ord, 'A');
}
{
char ord = TransUtil.getOrderdChar(9 + 26);
assertEquals(ord, 'Z');
assertEquals(ord, 'Z');
}
{
char ord = TransUtil.getOrderdChar(10 + 26);
assertEquals(ord, 'a');
assertEquals(ord, 'a');
}
{
char ord = TransUtil.getOrderdChar(9 + 26 + 26);
assertEquals(ord, 'z');
assertEquals(ord, 'z');
}
{
char ord = TransUtil.getOrderdChar(10 + 26 + 26);
assertEquals(ord, '0');
assertEquals(ord, '0');
}
}

Expand All @@ -999,7 +1000,16 @@ public void testDateTime() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd H:mm:ss zzz");
String s = formatter.format(zdtm);
System.out.println("testDateTime.format:" + s);
}


}

@Test
public void testZoneDateTime() {
System.out.println("testZoneDateTime");
ZoneId id = ZoneId.of("JST", ZoneId.SHORT_IDS);
System.out.println(id.getId());
System.out.println(id.getRules().getOffset(Instant.EPOCH));
System.out.println(id.getRules().toString());
}


}

0 comments on commit 8a49ef9

Please sign in to comment.