0

A date/time value is stored in our server as UTC which is correct. But when the server queries the date, it converts it to the server local time zone which is not necessarily the time zone of the device that has initiated the query. I am trying to simply adjust the time, based upon input parameters, to return it to UTC so it can be returned to the application in UTC. But when I try to parse the date so I can adjust the time, I run into a mask error.

I am having difficulty getting the right mask for this format: 2020-12-21T13:00:00.000+0000

Input Value: 2021-01-28T12:30:00.000+0000

Attempted mask: yyyy-MM-dd'T'HH:mm:ss

Error: No signature of method: java.text.SimpleDateFormat.parse() is applicable for argument types: (java.util.Date) values: {Thu Jan 28 12:30:00 UTC 2021} (in groovy script); Caused by: No signature of method: java.text.SimpleDateFormat.parse() is applicable for argument types: (java.util.Date) values: {Thu Jan 28 12:30:00 UTC 2021}

Code:

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

SimpleDateFormat inDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
SimpleDateFormat outDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
int minutesToAdd = (Hours * 60) + Minutes ;  
Calendar C = Calendar.getInstance();
java.util.Date D = inDate.parse(InputDate);
if (D!='')
     {
      C.setTime(D);
      C.add(Calendar.MINUTE, minutesToAdd);
      OutputDate=outDate.format(C.getTime());
     }
else
     {
      OutputDate = ''
     }

Any suggestions would be appreciated.

Vincent James
  • 1,120
  • 3
  • 16
  • 27
  • 2
    You are already passing a date into parse according to this error. Please add the code you have tried and how it failed (e.g. errors, stacktraces, logs, ...) so we can improve on it. – cfrick Jan 28 '21 at 15:27
  • 2
    JavaScript or Java? --- `java.text.` makes me think Java. – evolutionxbox Jan 28 '21 at 15:27
  • 1
    I recommend you don’t use `SimpleDateFormat` and `Date`. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use `OffsetDateTime` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Jan 28 '21 at 15:38
  • 1
    Related: [Cannot parse String in ISO 8601 format, lacking colon in offset, to Java 8 Date](https://stackoverflow.com/questions/43360852/cannot-parse-string-in-iso-8601-format-lacking-colon-in-offset-to-java-8-date) – Ole V.V. Jan 28 '21 at 15:39
  • 1
    I added the code. It fails on java.util.Date D = inDate.parse(InputDate); TY – Vincent James Jan 28 '21 at 15:48
  • This is the format of the DateTime being returned from SalesForce – Vincent James Jan 28 '21 at 15:49
  • Thank you evolutionxbox it is a Groovy 1.5 script – Vincent James Jan 28 '21 at 15:50
  • 3
    Above code works fine after massaging it to actually be stand-alone. I stand with my assessment, that `InputDate` is already a `java.util.Date`. – cfrick Jan 28 '21 at 16:57
  • @cfrick TY that makes sense. The input parameter type is being controlled by Boomi and as you said I suspect it is of type java.util.Date. – Vincent James Jan 28 '21 at 17:35
  • @cfrick So do you know of any solution since I am trapped using the java.util.Date? TY for your time – Vincent James Jan 29 '21 at 17:07
  • 1
    Not parsing a date that is already a date? I am quite confused about what you are asking. – cfrick Jan 29 '21 at 18:16
  • @cfrick The date is stored as UTC which is correct. But when the server queries the date, it converts it to the server local time zone which is not necessarily the time zone of the device that has initiated the query. I am trying to simply adjust the time, based upon input parameters, to return it to UTC so it can be returned to the application in UTC. But when I try to parse the date so I can adjust the time, I run into the mask issue. Some have said it is because there is no colon in the Time Zone portion of the data. I may be approaching this wrong. TY for your help. – Vincent James Jan 29 '21 at 18:33
  • 1
    @cfrick LOL really stupid of me. TY, I can just pass InputDate as is to the Calendar function now that I know it is the proper type. I will delete the post but I wanted you to see the comments first. I appreciate the help. TY – Vincent James Jan 29 '21 at 21:00
  • Even if in hindsight it looks stupid, please consider whether others could make a similar oversight and benefit from your question and your finding. If so it’s better to answer your own question (so not delete it). – Ole V.V. Jan 30 '21 at 04:41

1 Answers1

0

As cfrick suspected, the value being passed into the Groovy script from Boomi was of type java.util.Date and thus no parsing was needed.

TY

Vincent James
  • 1,120
  • 3
  • 16
  • 27