<commit_before>package ca.uhn.fhir.model.primitive;

import static org.junit.Assert.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import org.apache.commons.lang3.time.FastDateFormat;
import org.junit.Before;
import org.junit.Test;

import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.parser.DataFormatException;

public class BaseDateTimeDtTest {
	private SimpleDateFormat myDateInstantParser;
	private FastDateFormat myDateInstantZoneParser;
	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtTest.class);
	
	@Before
	public void before() {
		myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		myDateInstantZoneParser = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("GMT-02:00"));
	}
	
	@Test
	public void setTimezoneToZulu() {
		DateTimeDt dt = new DateTimeDt(new Date(816411488000L));
//		assertEquals("1995-11-14T23:58:08", dt.getValueAsString());
		dt.setTimeZoneZulu(true);
		assertEquals("1995-11-15T04:58:08Z", dt.getValueAsString());
	}
	

	@Test
	public void testFormats() throws Exception {
		Date instant = myDateInstantParser.parse("2001-02-03 13:01:02.555");
		for (FastDateFormat next : BaseDateTimeDt.getFormatters()) {
			
			GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("EST"));
			cal.setTime(instant);
			String value = next.format(cal);
			ourLog.info("String: {}", value);
			
			DateTimeDt dt = new DateTimeDt(value);
			String reEncoded = next.format(dt.getValue());
			<commit_msg>fixes a test which fails if the local time zone was not EST as the output from the formatter would change the offset of the reproduced string value.<commit_after>package ca.uhn.fhir.model.primitive;

import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.parser.DataFormatException;
import org.apache.commons.lang3.time.FastDateFormat;
import org.junit.Before;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

public class BaseDateTimeDtTest {
	private SimpleDateFormat myDateInstantParser;
	private FastDateFormat myDateInstantZoneParser;
	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtTest.class);
	
	@Before
	public void before() {
		myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		myDateInstantZoneParser = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("GMT-02:00"));
	}
	
	@Test
	public void setTimezoneToZulu() {
		DateTimeDt dt = new DateTimeDt(new Date(816411488000L));
//		assertEquals("1995-11-14T23:58:08", dt.getValueAsString());
		dt.setTimeZoneZulu(true);
		assertEquals("1995-11-15T04:58:08Z", dt.getValueAsString());
	}
	

	@Test
	public void testFormats() throws Exception {
		Date instant = myDateInstantParser.parse("2001-02-03 13:01:02.555");
		for (FastDateFormat next : BaseDateTimeDt.getFormatters()) {
			
			Calendar cal = Calendar.getInstance();
			cal.setTime(instant);
			String value = next.format(cal);
			ourLog.info("String: {}", value);
			
			DateTimeDt dt = new DateTimeDt(value);
			String reEncoded = next.format(dt.getValue());
			
{'fraction_non_alphanumeric': 0.11932479627473806, 'fraction_numerical': 0.037252619324796274, 'mean_word_length': 5.400372439478585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5567904', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1129, 'n_words': 222}