Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
import org.labkey.api.module.ModuleLoader;
import org.labkey.api.module.ModuleLoader.StartupPropertyStartupListener;
import org.labkey.api.module.ModuleXml;
import org.labkey.api.qc.TsvDataSerializerTestCase;
import org.labkey.api.query.AbstractQueryUpdateService;
import org.labkey.api.query.AliasManager;
import org.labkey.api.query.DetailsURL;
Expand Down Expand Up @@ -516,6 +517,7 @@ public void registerServlets(ServletContext servletCtx)
Table.IsSelectTestCase.class,
Table.LogExceptionTestCase.class,
TracedOperation.TestCase.class,
TsvDataSerializerTestCase.class,
URIUtil.TestCase.class,
UsageMetrics.TestCase.class,
ValidEmail.TestCase.class,
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/qc/TsvDataSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static void writeRow(Map<String, Object> row, List<String> columns, Prin
if (o != null)
{
if (Date.class.isAssignableFrom(o.getClass()))
pw.append(DateUtil.formatIsoDateShortTime((Date) o)); // Always ISO? Or should we apply display format?
pw.append(DateUtil.formatIsoDateLongTime((Date) o, true)); // GH Issue 1866: scripts pass values back for re-import, so keep full precision in one uniform shape
else if (MvFieldWrapper.class.isAssignableFrom(o.getClass()))
pw.append(String.valueOf(((MvFieldWrapper) o).getOriginalValue()));
else if (Collection.class.isAssignableFrom(o.getClass()))
Expand Down
72 changes: 72 additions & 0 deletions api/src/org/labkey/api/qc/TsvDataSerializerTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.api.qc;

import org.junit.Assert;
import org.junit.Test;
import org.labkey.api.data.TSVWriter;
import org.labkey.api.dataiterator.DataIteratorBuilder;
import org.labkey.api.dataiterator.MapDataIterator;
import org.labkey.api.util.DateUtil;
import org.labkey.api.util.FileUtil;
import org.labkey.vfs.FileLike;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class TsvDataSerializerTestCase extends Assert
{
@Test
public void testDateTimeKeepsSeconds() throws Exception
{
Date original = Date.from(LocalDateTime.of(2026, 3, 4, 10, 15, 42).atZone(ZoneId.systemDefault()).toInstant());
Map<String, Object> row = Map.of("Name", "a", "When", original);
DataIteratorBuilder dib = MapDataIterator.of(Set.of("Name", "When"), List.of(row));
TSVWriter tsvWriter = new TSVWriter()
{
@Override
protected int write()
{
throw new UnsupportedOperationException();
}
};

FileLike runDataFile = FileUtil.createTempFileLike("runData", ".tsv");
try
{
new TsvDataSerializer().exportRunData(null, List.of(dib), runDataFile, tsvWriter);

List<String> lines = Files.readAllLines(runDataFile.toNioPathForRead(), StandardCharsets.UTF_8);
assertEquals(2, lines.size());
int col = List.of(lines.get(0).split("\t")).indexOf("When");
assertTrue("Missing When column: " + lines.get(0), col >= 0);
String written = lines.get(1).split("\t")[col];
// Parse without DateUtil.parseDateTime(String), which reads LookAndFeelProperties from the database
long parsed = DateUtil.parseDateTime(written, DateUtil.MonthDayOption.MONTH_DAY, true, null);
assertEquals("Written value: " + written, original, new Date(parsed));
}
finally
{
runDataFile.delete();
}
}
}
Loading