hapi-server / server-java

Java-based server which works with Java-based web servers like Tomcat
Apache License 2.0
0 stars 1 forks source link

convert TimeUtil.java to TimeUtil.js #4

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
jbfaden commented 2 years ago

I found a new route to get this working. If I take the entire code, then replace toMillisecondsSince1970(time) and now() with stubs, remove the Logger statements, it can translate.

jbfaden commented 2 years ago

If there's a way to make the symbols be TimeUtil.xxx(), it would be much easier to make the translation. It would probably be nice to have the functions in a special namespace anyway.

rweigel commented 2 years ago

TimeUtil = {} TimeUtil.xxx = function (a) {return "yyy"+a} TimeUtil.xxx("q")

On Sun, Apr 10, 2022 at 8:16 AM Jeremy Faden @.***> wrote:

If there's a way to make the symbols be TimeUtil.xxx(), it would be much easier to make the translation. It would probably be nice to have the functions in a special namespace anyway.

— Reply to this email directly, view it on GitHub https://github.com/hapi-server/server-java/issues/4#issuecomment-1094259637, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUQ57RBFN5OQKQP6CGS5UDVELBBBANCNFSM5S7E76XA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jbfaden commented 2 years ago

Thanks, Bob. When I do the URI_Templates code, I'll use this form, and then I'll go back to the TimeUtil script.

jbfaden commented 2 years ago

This was moved over to https://github.com/hapi-server/uri-templates/issues/13

jbfaden commented 1 year ago

This task is done. See https://github.com/hapi-server/uri-templates/issues/13. Closing.