|
6 | 6 | import java.text.DecimalFormat;
|
7 | 7 | import java.text.DecimalFormatSymbols;
|
8 | 8 | import java.time.Duration;
|
| 9 | +import java.time.LocalDateTime; |
| 10 | +import java.time.ZoneOffset; |
| 11 | +import java.time.ZonedDateTime; |
9 | 12 | import java.util.Locale;
|
10 | 13 |
|
11 | 14 | import org.tinylog.Logger;
|
|
32 | 35 | @Param(name = "col_sample", type = Type.BOOLEAN, preset = "TRUE", description = "Include column 'sample' in CSV output. Folder path including filename.")
|
33 | 36 | @Param(name = "col_device", type = Type.BOOLEAN, preset = "TRUE", description = "Include column 'device' in CSV output.")
|
34 | 37 | @Param(name = "col_duration", type = Type.BOOLEAN, preset = "FALSE", description = "Include column 'duration' in CSV output.")
|
35 |
| -@Param(name = "col_time_zone", type = Type.BOOLEAN, preset = "FALSE", description = "Include column 'time_zone' in CSV output.") |
| 38 | +@Param(name = "col_original_time_zone", type = Type.BOOLEAN, preset = "FALSE", description = "Include column 'original_time_zone' of recording in CSV output. This may not be identical to the time zone of the 'time' column.") |
36 | 39 | @Param(name = "col_temperature", type = Type.BOOLEAN, preset = "FALSE", description = "Include column 'temperature' in CSV output.")
|
37 | 40 | @Param(name = "col_file_size", type = Type.BOOLEAN, preset = "FALSE", description = "Include column 'file_size' in CSV output and sum up total file size in log message.")
|
38 | 41 | @Param(name = "filename", type = Type.STRING, preset = "samples.csv", description = "Filename of output CSV-file.")
|
| 42 | +@Param(name = "time_zone", type = Type.STRING, preset = "", description = "Set time zone of the 'time' column. e.g. UTC+1 If left empty, default time zone of project will be set.") |
| 43 | +@Param(name = "include_time_zone", type = Type.BOOLEAN, preset = "FALSE", description = "In 'time' column, include the time zone marker. If false, time zone marker is not included in output, but time zone conversions are still applied.") |
39 | 44 | @Param(name = "filter_by_location", type = Type.STRING, preset = "", description = "(optional) Process the specified location only.")
|
40 | 45 | @Param(name = "filter_by_device", type = Type.STRING, preset = "", description = "(optional) Process the specified device id only.")
|
41 | 46 | @Param(name = "filter_by_time", type = Type.STRING, preset = "", description = "(optional) Process the specified range of time only. Format: yyyy-MM-ddTHH:mm:ss A shortened format leads to a range of time. e.g. 2022 means all samples from year 2022. e.g. 2022-02 means all samples from February at year 2022.")
|
@@ -64,10 +69,15 @@ public void run() {
|
64 | 69 | boolean col_sample = this.ctx.getParamBoolean("col_sample");
|
65 | 70 | boolean col_device = this.ctx.getParamBoolean("col_device");
|
66 | 71 | boolean col_duration = this.ctx.getParamBoolean("col_duration");
|
67 |
| - boolean col_time_zone = this.ctx.getParamBoolean("col_time_zone"); |
| 72 | + boolean col_original_time_zone = this.ctx.getParamBoolean("col_original_time_zone"); |
68 | 73 | boolean col_temperature = this.ctx.getParamBoolean("col_temperature");
|
69 | 74 | boolean col_file_size = this.ctx.getParamBoolean("col_file_size");
|
70 | 75 | String filename = this.ctx.getParamString("filename");
|
| 76 | + String reqTimeZone = this.ctx.getParamString("time_zone"); |
| 77 | + boolean include_time_zone = this.ctx.getParamBoolean("include_time_zone"); |
| 78 | + String tz = reqTimeZone.isBlank() ? ctx.broker.config().audioConfig.time_zone : reqTimeZone; |
| 79 | + int timeZoneOffsetSeconds = AudioTimeUtil.getTimeZoneOffsetSeconds(tz); |
| 80 | + ZoneOffset timeZoneOffset = include_time_zone ? ZoneOffset.ofTotalSeconds(timeZoneOffsetSeconds) : null; |
71 | 81 | String filter_by_location = this.ctx.getParamString("filter_by_location");
|
72 | 82 | String filter_by_device = this.ctx.getParamString("filter_by_device");
|
73 | 83 | String filter_by_time = this.ctx.getParamString("filter_by_time");
|
@@ -103,8 +113,8 @@ public void run() {
|
103 | 113 | if(col_duration) {
|
104 | 114 | cols.add("duration");
|
105 | 115 | }
|
106 |
| - if(col_time_zone) { |
107 |
| - cols.add("time_zone"); |
| 116 | + if(col_original_time_zone) { |
| 117 | + cols.add("original_time_zone"); |
108 | 118 | }
|
109 | 119 | if(col_temperature) {
|
110 | 120 | cols.add("temperature");
|
@@ -133,8 +143,15 @@ public void run() {
|
133 | 143 | row.add(location);
|
134 | 144 | }
|
135 | 145 | if(col_time) {
|
136 |
| - String timeName = AudioTimeUtil.ofAudiotime(sample.timestamp).toString(); |
137 |
| - row.add(timeName); |
| 146 | + LocalDateTime dt = AudioTimeUtil.ofAudiotime(sample.timestamp, timeZoneOffsetSeconds); |
| 147 | + if(include_time_zone) { |
| 148 | + ZonedDateTime zdt = ZonedDateTime.of(dt, timeZoneOffset); |
| 149 | + String timeName = zdt.toString(); |
| 150 | + row.add(timeName); |
| 151 | + } else { |
| 152 | + String timeName = dt.toString(); |
| 153 | + row.add(timeName); |
| 154 | + } |
138 | 155 | }
|
139 | 156 | if(col_path || col_filename || col_sample) {
|
140 | 157 | Path path = root_data_path.relativize(sample.samplePath);
|
@@ -165,7 +182,7 @@ public void run() {
|
165 | 182 | row.add("NA");
|
166 | 183 | }
|
167 | 184 | }
|
168 |
| - if(col_time_zone) { |
| 185 | + if(col_original_time_zone) { |
169 | 186 | String utc_ = sample.getUTC();
|
170 | 187 | String utc = utc_ == null ? "" : utc_;
|
171 | 188 | row.add(utc);
|
|
0 commit comments