2626import java .time .ZoneId ;
2727import java .time .ZonedDateTime ;
2828import java .time .format .DateTimeFormatter ;
29- import java .time .format .TextStyle ;
3029import com .kosherjava .zmanim .AstronomicalCalendar ;
3130
3231/**
@@ -349,13 +348,15 @@ public String formatXSDDurationTime(Time time) {
349348 * format used is:
350349 *
351350 * <pre>
352- * <AstronomicalTimes date="1969-02-08" type="com.kosherjava.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ " latitude="40.095965 " longitude="-74.22213 " elevation="31 .0" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5">
353- * <Sunrise >2007 -02-18T06:45:27 -05:00</Sunrise >
354- * <TemporalHour>PT54M17.529S </TemporalHour>
351+ * <AstronomicalTimes date="1969-02-08" type="com.kosherjava.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Montreal, Quebec " latitude="45.497 " longitude="-73.63 " elevation="85 .0" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5">
352+ * <SeaLevelSunset >1969 -02-08T17:11:26 -05:00</SeaLevelSunset >
353+ * <TemporalHour>PT50M23.259S </TemporalHour>
355354 * ...
356355 * </AstronomicalTimes>
357356 * </pre>
358357 *
358+ * If a zman does not occur, the value "N/A" will be returned.
359+ *
359360 * Note that the output uses the <a href="http://www.w3.org/TR/xmlschema11-2/#dateTime">xsd:dateTime</a> format for
360361 * times such as sunrise, and <a href="http://www.w3.org/TR/xmlschema11-2/#duration">xsd:duration</a> format for
361362 * times that are a duration such as the length of a
@@ -364,15 +365,7 @@ public String formatXSDDurationTime(Time time) {
364365 *
365366 * @param astronomicalCalendar the AstronomicalCalendar Object
366367 *
367- * @return The XML formatted <code>String</code>. The format will be:
368- *
369- * <pre>
370- * <AstronomicalTimes date="1969-02-08" type="com.kosherjava.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ" latitude="40.095965" longitude="-74.22213" elevation="31.0" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5">
371- * <Sunrise>2007-02-18T06:45:27-05:00</Sunrise>
372- * <TemporalHour>PT54M17.529S</TemporalHour>
373- * ...
374- * </AstronomicalTimes>
375- * </pre>
368+ * @return The XML <code>String</code> formatted as described above.
376369 *
377370 * @todo Add proper schema, and support for nulls. XSD duration (for solar hours), should probably return nil and not P.
378371 */
@@ -383,7 +376,10 @@ public static String toXML(AstronomicalCalendar astronomicalCalendar) {
383376 df = df .withZone (astronomicalCalendar .getGeoLocation ().getZoneId ());
384377
385378 LocalDate localDate = astronomicalCalendar .getLocalDate ();
386- ZoneId zi = astronomicalCalendar .getGeoLocation ().getZoneId ();
379+ GeoLocation geoLocation = astronomicalCalendar .getGeoLocation ();
380+ ZonedDateTime lastMidnight = ZonedDateTime .of (astronomicalCalendar .getLocalDate (), LocalTime .MIDNIGHT , astronomicalCalendar .getGeoLocation ().getZoneId ());
381+ double offsetHours = lastMidnight .getOffset ().getTotalSeconds () / 3600.0 ;
382+ String timeZoneName = lastMidnight .format (DateTimeFormatter .ofPattern ("zzzz" , Locale .getDefault ()));
387383
388384 StringBuilder sb = new StringBuilder ("<" );
389385 boolean isAstronomicalCalendar = astronomicalCalendar .getClass ().getName ().equals ("com.kosherjava.zmanim.AstronomicalCalendar" );
@@ -412,14 +408,10 @@ public static String toXML(AstronomicalCalendar astronomicalCalendar) {
412408 sb .append (" latitude=\" " ).append (astronomicalCalendar .getGeoLocation ().getLatitude ()).append ("\" " );
413409 sb .append (" longitude=\" " ).append (astronomicalCalendar .getGeoLocation ().getLongitude ()).append ("\" " );
414410 sb .append (" elevation=\" " ).append (astronomicalCalendar .getGeoLocation ().getElevation ()).append ("\" " );
415- sb .append (" timeZoneName=\" " ).append (zi .getDisplayName (TextStyle .FULL , Locale .getDefault ())).append ("\" " );
416- sb .append (" timeZoneID=\" " ).append (zi .getId ()).append ("\" " );
417-
418- ZonedDateTime lastMidnight = ZonedDateTime .of (astronomicalCalendar .getLocalDate (), LocalTime .MIDNIGHT , astronomicalCalendar .getGeoLocation ().getZoneId ());
419- double offsetHours = lastMidnight .getOffset ().getTotalSeconds () / 3600.0 ;
411+ sb .append (" timeZoneName=\" " ).append (timeZoneName ).append ("\" " );
412+ sb .append (" timeZoneID=\" " ).append (geoLocation .getZoneId ().getId ()).append ("\" " );
420413 sb .append (" timeZoneOffset=\" " ).append (offsetHours ).append ("\" " );
421414 //sb.append(" useElevationAllZmanim=\"").append(astronomicalCalendar.useElevationAllZmanim()).append("\""); //TODO likely using reflection
422-
423415 sb .append (">\n " );
424416
425417 Method [] theMethods = astronomicalCalendar .getClass ().getMethods ();
@@ -497,16 +489,16 @@ public static String toXML(AstronomicalCalendar astronomicalCalendar) {
497489 * "date":"1969-02-08",
498490 * "type":"com.kosherjava.zmanim.AstronomicalCalendar",
499491 * "algorithm":"US Naval Almanac Algorithm",
500- * "location":"Lakewood, NJ ",
501- * "latitude":"40.095965 ",
502- * "longitude":"-74.22213 ",
503- * "elevation:"31 .0",
492+ * "location":"Montreal, Quebec ",
493+ * "latitude":"45.497 ",
494+ * "longitude":"-73.63 ",
495+ * "elevation:"85 .0",
504496 * "timeZoneName":"Eastern Standard Time",
505497 * "timeZoneID":"America/New_York",
506498 * "timeZoneOffset":"-5"},
507499 * "AstronomicalTimes":{
508- * "Sunrise ":"2007 -02-18T06:45:27 -05:00",
509- * "TemporalHour":"PT54M17.529S "
500+ * "SeaLevelSunset ":"1969 -02-08T17:11:26 -05:00",
501+ * "TemporalHour":"PT50M23.259S "
510502 * ...
511503 * }
512504 * }
@@ -516,30 +508,11 @@ public static String toXML(AstronomicalCalendar astronomicalCalendar) {
516508 * times such as sunrise, and <a href="http://www.w3.org/TR/xmlschema11-2/#duration">xsd:duration</a> format for
517509 * times that are a duration such as the length of a
518510 * {@link com.kosherjava.zmanim.AstronomicalCalendar#getTemporalHour() temporal hour}.
511+ * If a zman does not occur, the value "N/A" will be returned.
519512 *
520513 * @param astronomicalCalendar the AstronomicalCalendar Object
521514 *
522- * @return The JSON formatted <code>String</code>. The format will be:
523- * <pre>
524- * {
525- * "metadata":{
526- * "date":"1969-02-08",
527- * "type":"com.kosherjava.zmanim.AstronomicalCalendar",
528- * "algorithm":"US Naval Almanac Algorithm",
529- * "location":"Lakewood, NJ",
530- * "latitude":"40.095965",
531- * "longitude":"-74.22213",
532- * "elevation:"31.0",
533- * "timeZoneName":"Eastern Standard Time",
534- * "timeZoneID":"America/New_York",
535- * "timeZoneOffset":"-5"},
536- * "AstronomicalTimes":{
537- * "Sunrise":"2007-02-18T06:45:27-05:00",
538- * "TemporalHour":"PT54M17.529S"
539- * ...
540- * }
541- * }
542- * </pre>
515+ * @return The JSON <code>String</code> formatted as described above.
543516 */
544517 public static String toJSON (AstronomicalCalendar astronomicalCalendar ) {
545518 ZmanimFormatter formatter = new ZmanimFormatter (ZmanimFormatter .XSD_DURATION_FORMAT , DateTimeFormatter .ofPattern (
@@ -548,23 +521,22 @@ public static String toJSON(AstronomicalCalendar astronomicalCalendar) {
548521 .withZone (astronomicalCalendar .getGeoLocation ().getZoneId ());
549522
550523 LocalDate localDate = astronomicalCalendar .getLocalDate ();
551- ZoneId zi = astronomicalCalendar .getGeoLocation ().getZoneId ();
524+ GeoLocation geoLocation = astronomicalCalendar .getGeoLocation ();
525+ ZonedDateTime lastMidnight = ZonedDateTime .of (astronomicalCalendar .getLocalDate (), LocalTime .MIDNIGHT ,
526+ astronomicalCalendar .getGeoLocation ().getZoneId ());
527+ double offsetHours = lastMidnight .getOffset ().getTotalSeconds () / 3600.0 ;
528+ String timeZoneName = lastMidnight .format (DateTimeFormatter .ofPattern ("zzzz" , Locale .getDefault ()));
552529
553530 StringBuilder sb = new StringBuilder ("{\n \" metadata\" :{\n " );
554531 sb .append ("\t \" date\" :\" " ).append (df .format (localDate )).append ("\" ,\n " );
555532 sb .append ("\t \" type\" :\" " ).append (astronomicalCalendar .getClass ().getName ()).append ("\" ,\n " );
556533 sb .append ("\t \" algorithm\" :\" " ).append (astronomicalCalendar .getAstronomicalCalculator ().getCalculatorName ()).append ("\" ,\n " );
557- sb .append ("\t \" location\" :\" " ).append (astronomicalCalendar .getGeoLocation ().getLocationName ()).append ("\" ,\n " );
558- sb .append ("\t \" latitude\" :\" " ).append (astronomicalCalendar .getGeoLocation ().getLatitude ()).append ("\" ,\n " );
559- sb .append ("\t \" longitude\" :\" " ).append (astronomicalCalendar .getGeoLocation ().getLongitude ()).append ("\" ,\n " );
560- sb .append ("\t \" elevation\" :\" " ).append (astronomicalCalendar .getGeoLocation ().getElevation ()).append ("\" ,\n " );
561-
562-
563- sb .append ("\t \" timeZoneName\" :\" " ).append (zi .getDisplayName (TextStyle .FULL , Locale .getDefault ())).append ("\" ,\n " );
564- sb .append ("\t \" timeZoneID\" :\" " ).append (zi .getId ()).append ("\" ,\n " ); //FIXME
565-
566- ZonedDateTime lastMidnight = ZonedDateTime .of (astronomicalCalendar .getLocalDate (), LocalTime .MIDNIGHT , astronomicalCalendar .getGeoLocation ().getZoneId ());
567- double offsetHours = lastMidnight .getOffset ().getTotalSeconds () / 3600.0 ;
534+ sb .append ("\t \" location\" :\" " ).append (geoLocation .getLocationName ()).append ("\" ,\n " );
535+ sb .append ("\t \" latitude\" :\" " ).append (geoLocation .getLatitude ()).append ("\" ,\n " );
536+ sb .append ("\t \" longitude\" :\" " ).append (geoLocation .getLongitude ()).append ("\" ,\n " );
537+ sb .append ("\t \" elevation\" :\" " ).append (geoLocation .getElevation ()).append ("\" ,\n " );
538+ sb .append ("\t \" timeZoneName\" :\" " ).append (timeZoneName ).append ("\" ,\n " );
539+ sb .append ("\t \" timeZoneID\" :\" " ).append (geoLocation .getZoneId ().getId ()).append ("\" ,\n " );
568540 sb .append ("\t \" timeZoneOffset\" :\" " ).append (offsetHours ).append ("\" " );
569541 sb .append ("},\n \" " );
570542
0 commit comments