Project

General

Profile

Revision dc12a332

IDdc12a33235c1926bf526ffc9a04306f6c0758e75
Parent 7a023b3e
Child c1489d4e

Added by Katja Luther almost 4 years ago

ref #6860: use timezone offset 0 and change joda DateTime to ZonedDateTime, until in lib DateTime is still joda a converter is used

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DateConverter.java
1
package eu.etaxonomy.taxeditor.model;
2

  
3
import java.time.ZoneId;
4
import java.time.ZonedDateTime;
5

  
6
import org.joda.time.DateTime;
7
import org.joda.time.DateTimeZone;
8

  
9
public class DateConverter {
10
	
11
	public static ZonedDateTime convertJoda2ZonedDateTime(DateTime dateTime){
12
		ZonedDateTime result = null;
13
		result = ZonedDateTime.of(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), 0, 0, convertJodaTimeZone2ZoneId(dateTime.getZone()));
14
		
15
		
16
		return result;
17
	}
18
	
19
	public static DateTime convertZonedDateTime2Joda(ZonedDateTime dateTime){
20
		DateTime result = null;
21
		result = new DateTime(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth(), dateTime.getHour(), dateTime.getMinute(), 0, convertZoneId2JodaTimeZone(dateTime.getZone()));
22
		
23
		
24
		return result;
25
	}
26
	
27
	public static ZoneId convertJodaTimeZone2ZoneId(DateTimeZone jodaZone){
28
		ZoneId zoneId = null;
29
		
30
		zoneId = ZoneId.of(jodaZone.getID());
31
		
32
		return zoneId;
33
	}
34
	
35
	public static DateTimeZone convertZoneId2JodaTimeZone(ZoneId zoneid){
36
		DateTimeZone jodaZone = null;
37
		
38
		jodaZone = DateTimeZone.forID(zoneid.getId());
39
		
40
		return jodaZone;
41
	}
42

  
43
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/DateElement.java
9 9
package eu.etaxonomy.taxeditor.ui.mvc.element;
10 10

  
11 11

  
12
import java.time.ZoneId;
13
import java.time.ZonedDateTime;
14
import java.time.format.DateTimeFormatter;
15

  
16
import org.apache.lucene.analysis.shingle.ShingleMatrixFilter.OneDimensionalNonWeightedTokenSettingsCodec;
12 17
import org.eclipse.swt.SWT;
13 18
import org.eclipse.swt.events.DisposeEvent;
14 19
import org.eclipse.swt.events.DisposeListener;
......
41 46
public class DateElement extends AbstractCdmComposite<DateElementController>  {
42 47

  
43 48
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
44
    private org.joda.time.DateTime initialDateTime;
49
    private ZonedDateTime initialDateTime;
45 50
    private Text textDate;
46 51
    private final Button openDateDialog;
47 52
    
......
53 58
     * @param parent
54 59
     * @param style
55 60
     */
56
    public DateElement(Composite parent, org.joda.time.DateTime initialDateTime, String label, int style, boolean editableText) {
61
    public DateElement(Composite parent, ZonedDateTime initDateTime, String label, int style, boolean editableText) {
57 62
        super(parent, style);
58
        this.initialDateTime = initialDateTime;
63
        this.initialDateTime = initDateTime;
64
        
65
        
59 66
        addDisposeListener(new DisposeListener() {
60 67
            @Override
61 68
            public void widgetDisposed(DisposeEvent e) {
......
109 116
    			
110 117
    			final DateTime time = new DateTime (dialog, SWT.TIME | SWT.SHORT);
111 118
    			if (initialDateTime != null){
112
    				calendar.setDate(initialDateTime.getYear(), initialDateTime.getMonthOfYear() - 1, initialDateTime.getDayOfMonth());
113
    				time.setHours(initialDateTime.getHourOfDay());
114
        			time.setMinutes(initialDateTime.getMinuteOfHour());
115
        			time.setSeconds(initialDateTime.getSecondOfMinute());
119
    				calendar.setDate(initialDateTime.getYear(), initialDateTime.getMonthValue()-1, initialDateTime.getDayOfMonth());
120
    				time.setHours(initialDateTime.getHour());
121
        			time.setMinutes(initialDateTime.getMinute());
122
//        			time.setSeconds(initialDateTime.getSecondOfMinute());
116 123
    			}
117 124
    			
118 125

  
......
124 131
    			ok.addSelectionListener (new SelectionAdapter() {
125 132
    	        	@Override
126 133
    	        	public void widgetSelected(SelectionEvent e){
127
    	        		setData(makeJodaFromSWT(calendar, time));
134
    	        		setData(makeZonedTimeFromSWT(calendar, time));
128 135
    	        		dialog.close ();
129 136
    				}
130 137
    			});
......
149 156
   
150 157
    
151 158
	
152
    public static org.joda.time.DateTime makeJodaFromSWT(
159
    public static ZonedDateTime makeZonedTimeFromSWT(
153 160
	                                org.eclipse.swt.widgets.DateTime widget, 
154 161
	                                org.eclipse.swt.widgets.DateTime dateTime) {
155 162
		  //the first month of the year is 0			  
156
		  return new org.joda.time.DateTime(widget.getYear(),
157
	                        widget.getMonth() +1,
158
	                        widget.getDay(),
159
	                        dateTime.getHours(),
160
	                        dateTime.getMinutes(),
161
	                        dateTime.getSeconds());
163
		  return ZonedDateTime.of(widget.getYear(),
164
				  widget.getMonth()+1,
165
				  widget.getDay(),
166
				  dateTime.getHours(),
167
				  dateTime.getMinutes(),
168
                  0,
169
                  0,
170
                  ZoneId.of("UTC"));
162 171
	}
163 172

  
164 173
	public static void updateSWTwithJoda(
165 174
	                                org.eclipse.swt.widgets.DateTime widget,
166
	                                org.joda.time.DateTime dateTime) {
175
	                                ZonedDateTime dateTime) {
167 176
		  widget.setYear(dateTime.getYear());
168
		  widget.setMonth(dateTime.getMonthOfYear() - 1);
177
		  widget.setMonth(dateTime.getMonthValue() -1);
169 178
		  widget.setDay(dateTime.getDayOfMonth());
170
		  widget.setHours(dateTime.getHourOfDay());
171
		  widget.setMinutes(dateTime.getMinuteOfHour());
172
		  widget.setSeconds(dateTime.getSecondOfMinute());
179
		  widget.setHours(dateTime.getHour());
180
		  widget.setMinutes(dateTime.getMinute());
181
		  widget.setSeconds(dateTime.getSecond());
173 182
	}
174 183
		
175
	public void setData (org.joda.time.DateTime data) {
184
	public void setData (ZonedDateTime data) {
176 185
			this.initialDateTime = data;
177 186
			this.controller.setDateTime(data);
178
			this.textDate.setText(initialDateTime.toString(pattern));
187
			this.textDate.setText(initialDateTime.format(DateTimeFormatter.ofPattern(pattern)));
179 188
	}
180 189

  
181 190
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/mvc/element/DateElementController.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.ui.mvc.element;
10 10

  
11
import java.time.ZonedDateTime;
12
import java.time.format.DateTimeFormatter;
13

  
11 14
import org.eclipse.swt.events.ModifyEvent;
12 15
import org.eclipse.swt.events.ModifyListener;
13 16
import org.eclipse.swt.widgets.Text;
......
28 31
public class DateElementController extends AbstractCdmFormElement implements IEnableableFormElement, CdmCompositeController, ModifyListener{
29 32

  
30 33
    private final Text textDate;
31
    private DateTime dateTime;
34
    private ZonedDateTime dateTime;
32 35

  
33 36
    /**
34 37
     * @param dateTimeElement
......
38 41
     * @param none
39 42
     */
40 43
    public DateElementController(DateElement dateTimeElement, CdmFormFactory formFactory, 
41
    		ICdmFormElement parentElement, DateTime initialDateTime) {
44
    		ICdmFormElement parentElement, ZonedDateTime initialDateTime) {
42 45
        super(formFactory, parentElement);
43 46
        this.textDate = dateTimeElement.getTextDate();
44
        if (initialDateTime != null){
45
        	this.textDate.setText(initialDateTime.toString("yyyy-MM-dd HH:mm"));
46
        }
47
        // this.textDate.setText(initialDateTime!=null?initialDateTime.toString("yyyy-MM-dd HH:mm"):null);
47
//        if (initialDateTime != null){
48
//        	this.textDate.setText(initialDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
49
//        }
50
         this.textDate.setText(initialDateTime!=null?initialDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")):"");
48 51
        addControl(textDate);
49 52
        dateTime = initialDateTime;
50 53
        textDate.addModifyListener(this);
......
71 74
        }
72 75
    }
73 76

  
74
    public DateTime getDateTime(){
77
    public ZonedDateTime getDateTime(){
75 78
        return dateTime;
76 79
    } 
77
    public void setDateTime(DateTime date){
80
    public void setDateTime(ZonedDateTime date){
78 81
       dateTime = date;
79 82
    } 
80 83

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java
3 3
 */
4 4
package eu.etaxonomy.taxeditor.ui.section.media;
5 5

  
6
import java.time.ZonedDateTime;
6 7
import java.util.Map;
7 8

  
8 9
import org.eclipse.jface.action.IAction;
......
11 12
import org.eclipse.swt.events.SelectionListener;
12 13

  
13 14
import org.eclipse.swt.widgets.Button;
15
import org.joda.time.DateTime;
16

  
14 17
import eu.etaxonomy.cdm.common.CdmUtils;
15 18
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
16 19
import eu.etaxonomy.cdm.model.agent.AgentBase;
......
18 21
import eu.etaxonomy.cdm.model.common.LanguageString;
19 22
import eu.etaxonomy.cdm.model.media.Media;
20 23
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24
import eu.etaxonomy.taxeditor.model.DateConverter;
21 25
import eu.etaxonomy.taxeditor.model.ImageResources;
22 26
import eu.etaxonomy.taxeditor.store.CdmStore;
23 27
import eu.etaxonomy.taxeditor.ui.dialog.selection.MediaSelectionDialog;
......
74 78
        text_title = formFactory.createLanguageStringWithLabelElement(element, "Title", null, style);
75 79
        selection_artist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), element, "Artist", null, EntitySelectionElement.ALL, style);
76 80
        addElement(selection_artist);
77
        mediaCreated = formFactory.createDateElement(element, "Media Created", getEntity().getMediaCreated(), style, false);
81
        ZonedDateTime mediaCreatedValue = null;
82
        if (getEntity().getMediaCreated() != null){
83
        	mediaCreatedValue =  DateConverter.convertJoda2ZonedDateTime(getEntity().getMediaCreated());
84
        }
85
        mediaCreated = formFactory.createDateElement(element, "Media Created", mediaCreatedValue, style, false);
78 86
        addElement(mediaCreated.getController());
79 87
        text_description = formFactory.createLanguageStringWithLabelElement(element, "Description", null, 100, true, style);
80 88
        
......
139 147
                ((AbstractCdmDetailSection<?>) getParentElement()).updateTitle();
140 148
            }
141 149
        } else if (eventSource == mediaCreated.getController()){
142
        	org.joda.time.DateTime date = mediaCreated.getController().getDateTime();
150
        	DateTime date = DateConverter.convertZonedDateTime2Joda(mediaCreated.getController().getDateTime());
143 151
        	getEntity().setMediaCreated(date);
144 152
        }
145 153
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/DnaQualityDetailElement.java
14 14
import eu.etaxonomy.cdm.model.common.TermType;
15 15
import eu.etaxonomy.cdm.model.molecular.DnaQuality;
16 16
import eu.etaxonomy.cdm.model.molecular.DnaSample;
17
import eu.etaxonomy.taxeditor.model.DateConverter;
17 18
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
18 19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19 20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
......
68 69
        numberRatioOfAbsorbance260_230 = formFactory.createNumberTextWithLabelElement(formElement, "Ratio of absorbance 260-230", ratioOfAbsorbance260_230, style);
69 70
        numberConcentration = formFactory.createNumberTextWithLabelElement(formElement, "Concentration", concentration, style);
70 71
        comboQualityTerm = formFactory.createDefinedTermComboElement(TermType.DnaQualityType, formElement, "Quality Term", qualityTerm, style);
71
        dateQualityCheck = formFactory.createDateElement(formElement, "Quality Check", dnaQuality.getQualityCheckDate(), style, false);
72
        dateQualityCheck = formFactory.createDateElement(formElement, "Quality Check", DateConverter.convertJoda2ZonedDateTime(dnaQuality.getQualityCheckDate()), style, false);
72 73
    }
73 74

  
74 75
    /*
......
97 98
            dnaQuality.setQualityTerm(comboQualityTerm.getSelection());
98 99
        }
99 100
        else if(eventSource==dateQualityCheck.getController()){
100
            DateTime dateTime = dateQualityCheck.getController().getDateTime();
101
            DateTime dateTime = DateConverter.convertZonedDateTime2Joda(dateQualityCheck.getController().getDateTime());
102
            
101 103
            dnaQuality.setQualityCheckDate(dateTime);
102 104
        }
103 105
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/media/MediaSpecimenGeneralDetailElement.java
22 22
import eu.etaxonomy.cdm.model.occurrence.Collection;
23 23
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
24 24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.taxeditor.model.DateConverter;
25 26
import eu.etaxonomy.taxeditor.store.CdmStore;
26 27
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
27 28
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
......
73 74
            comboKindOfUnit = formFactory.createDefinedTermComboElement(mediaSpecimenVocabulary, formElement, "Kind of Media", entity.getKindOfUnit(), style);
74 75
            textTitleLanguageString = formFactory.createLanguageStringWithLabelElement(formElement, "Motif", media.getTitle(), style);
75 76
            selectionArtist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), formElement, "Prepared by", media.getArtist(), EntitySelectionElement.ALL, style);
76
            date = formFactory.createDateElement(formElement, "Preparation Date", entity.getMediaSpecimen().getMediaCreated(), style, true);
77
            date = formFactory.createDateElement(formElement, "Preparation Date", DateConverter.convertJoda2ZonedDateTime(entity.getMediaSpecimen().getMediaCreated()), style, true);
77 78
            textMethodLanguageString = formFactory.createLanguageStringWithLabelElement(formElement, "Method", media.getDescription(Language.getDefaultLanguage()), style);
78 79
            selection_collection = formFactory.createSelectionElement(Collection.class, getConversationHolder(), formElement, "Collection", entity.getCollection(), EntitySelectionElement.ALL, style);
79 80
            text_accessionNumber = formFactory.createTextWithLabelElement(formElement, "Accession Number", entity.getAccessionNumber(), style);
......
108 109
            media.putTitle(textTitleLanguageString.getLanguageString());
109 110
        }
110 111
        else if(eventSource==date.getController()){
111
            DateTime dateTime = date.getController().getDateTime();
112
            DateTime dateTime = DateConverter.convertZonedDateTime2Joda(date.getController().getDateTime());
112 113
            media.setMediaCreated(dateTime);
113 114
        }
114 115
        else if(eventSource==selectionArtist){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java
24 24
import eu.etaxonomy.cdm.model.reference.Reference;
25 25
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
26 26
import eu.etaxonomy.cdm.model.reference.ReferenceType;
27
import eu.etaxonomy.taxeditor.model.DateConverter;
27 28
import eu.etaxonomy.taxeditor.store.CdmStore;
28 29
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
29 30
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
......
186 187
	}
187 188

  
188 189
	private void createWebPageControls(ReferenceDetailElement referenceDetailElement, Reference reference, int style) {
189
		 text_accessed = formFactory.createDateElement(referenceDetailElement, "Accessed", reference.getAccessed(), style, false);
190
		 text_accessed = formFactory.createDateElement(referenceDetailElement, "Accessed", DateConverter.convertJoda2ZonedDateTime(reference.getAccessed()), style, false);
190 191
		
191 192
	}
192 193

  
......
480 481
		} else if (eventSource == text_volume) {
481 482
			getEntity().setVolume(text_volume.getText());
482 483
		}else if (eventSource == text_accessed.getController()) {
483
			getEntity().setAccessed(text_accessed.getController().getDateTime());
484
			getEntity().setAccessed(DateConverter.convertZonedDateTime2Joda(text_accessed.getController().getDateTime()));
484 485
		}
485 486

  
486 487
		if (eventSource != text_title && eventSource != text_abbrevTitle) {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)