hapi-server / uri-templates

Repository of tools for URI templates
Apache License 2.0
2 stars 0 forks source link

convert TimeUtil.java to TimeUtil.js, URI_Template.java to URI_Template.js #13

Closed jbfaden closed 1 year ago

jbfaden commented 2 years ago

TimeUtil.java was always intended to be ported to other languages, and I'm curious how the port to JavaScript would go. I've been using the site https://www.jsweet.org/jsweet-live-sandbox/ to convert the code piece by piece, because it isn't working for the entire code, and it produces somewhat unreadable code anyway.

This is a table of function name in Java and if it is ported to JavaScript:

Java JavaScript
final int TIME_DIGITS = 7; Y
final int DATE_DIGITS = 3; Y
String reformatIsoTime(String exampleForm, String time) Y
String monthNameAbbrev(int i) Y
int monthNumber(String s) throws ParseException Y
String[] countOffDays(String startTime, String stopTime) Y
String nextDay(String day) Y
String previousDay(String day) Y
String ceil(String time) Y
String floor(String time) Y
String normalizeTimeString(String time) Y
String isoTimeFromArray(int[] nn) Y
String formatIso8601TimeRange( int[] nn ) Y
String formatIso8601Time( int[] nn, int offset ) Y
String formatIso8601Time( int[] nn ) Y
String formatIso8601Duration(int[] nn) Y
int[] now() Y
int[] isoTimeToArray(String time) Y
int dayOfYear(int year, int month, int day) Y
int monthForDayOfYear( int year, int doy ) Y
long toMillisecondsSince1970(String time) Y
void normalizeTime(int[] time) Y
int dayOfWeek( int year, int month, int day ) Y
void fromWeekOfYear( int year, int weekOfYear, int[] time ) Y
int[] parseISO8601Duration(String stringIn) Y
int[] parseISO8601Time( String string ) Y
int[] parseISO8601TimeRange(String stringIn) Y
int julianDay(int year, int month, int day) Y
int[] fromJulianDay(int julian) Y
int[] subtract(int[] base, int[] offset) Y
int[] add(int[] base, int[] offset) Y

This was moved over from https://github.com/hapi-server/server-java/issues/4

jbfaden commented 2 years ago

@rweigel and I were using jsweet last week, but I've also just found https://www.stratacode.com/javaToJS/online.html. This one allows multiple Java classes to be uploaded (TimeUtil.java is needed for URI_Templates to work).

jbfaden commented 1 year ago

See also https://github.com/hapi-server/uri-templates/issues/14

jbfaden commented 1 year ago

I had an unusual opportunity to work on this last week (Covid!) and I made a translator similar to the Python translator. This is done enough to easily do TimeUtil.js now, and the unit test for TimeUtil.js. The converter is here: https://cottagesystems.com/JavaJythonConverter/ConvertJavaToJavascriptServlet. I need to return to this and finish off URI_Templates.java.

jbfaden commented 1 year ago

See https://github.com/hapi-server/uri-templates/blob/master/UriTemplatesJavaScript/TimeUtil.js

jbfaden commented 1 year ago

This is done, or at least passing all the regression tests.

jbfaden commented 1 year ago

See https://github.com/hapi-server/uri-templates/tree/master/UriTemplatesJavaScript