1 /* Contributed in the public domain.
2 * Licensed to CS GROUP (CS) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * CS licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.orekit.utils;
18
19 import org.orekit.time.DateComponents;
20 import org.orekit.time.DateTimeComponents;
21 import org.orekit.time.TimeComponents;
22
23 import java.util.Locale;
24
25 /** Formatter used to produce strings from data.
26 * <p>
27 * Interface for formatters to be passed to generators, dictating how to write doubles and datetime.
28 * </p>
29 * @author John Ajamian
30 * @since 13.0
31 */
32 public interface Formatter {
33
34 /**
35 * Standardized locale to use, to ensure files can be exchanged without
36 * internationalization issues.
37 */
38 Locale STANDARDIZED_LOCALE = Locale.US;
39
40 /** String format used for dates. **/
41 String DATE_FORMAT = "%04d-%02d-%02dT%02d:%02d:%s";
42
43 /**
44 * Format a double number.
45 *
46 * @param value number to format
47 * @return number formatted.
48 */
49 String toString(double value);
50
51 /** Format a date. Does not check if date time is real or if it will meet formating requirements.
52 * @param year of date to be formatted
53 * @param month of date to be formatted
54 * @param day of month to be formatted
55 * @param hour to be formatted
56 * @param minute to be formatted
57 * @param seconds and sub-seconds to be formatted
58 * @return date formatted to match the following format [yyyy-MM-ddTHH:mm:ss.S#]
59 */
60 String toString(int year, int month, int day, int hour, int minute, double seconds);
61
62 /**
63 * Format date time components to make use of attosecond accuracy from {@link org.orekit.time.TimeOffset}. Does not
64 * check if date time is real or if it will meet formating requirements.
65 *
66 * @param dt date time components to be formatted
67 * @return date formatted to match the following format [yyyy-MM-ddTHH:mm:ss.S#]
68 * @since 13.1.6
69 */
70 default String toString(DateTimeComponents dt) {
71 final DateComponents date = dt.getDate();
72 final TimeComponents time = dt.getTime();
73 return toString(date.getYear(), date.getMonth(), date.getDay(),
74 time.getHour(), time.getMinute(), time.getSecond());
75 }
76
77 }