Skip to content

sendDate ignores hour #40

Description

@tm13

When calling send on a Campaigns instance the provided Date sendDate parameter gets stripped of the time.
It will always fall back to 12:00 AM.

Activity

  1. zischler commented on Aug 14, 2019

    @zischler

    Experienced the same. I guess the DateFormat is wrong in that case.

    package com.createsend.util.jersey;
    
    /**
     * An extension of the Jersey JacksonJsonProvider used to set Jackson 
     * serialisation/deserialisation properties
     */
    public class JsonProvider extends JacksonJsonProvider {
    
        public static final DateFormat ApiDateFormat = new SimpleDateFormat("yyyy-MM-dd") {
            final SimpleDateFormat ApiDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            final SimpleDateFormat ApiDateFormatTz = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    
            @Override
            public Date parse(String source, ParsePosition pos) {
                if (source.length() - pos.getIndex() == ApiDateFormat.toPattern().length())
                    return ApiDateFormat.parse(source, pos);
                return ApiDateFormatTz.parse(source, pos);
            }
        };
    
  2. zischler commented on Aug 15, 2019

    @zischler

    For our project I rewrote com.createsend.Campaigns.send(...)

      /**
        * Sends an existing draft campaign using the provided confirmation email and send date.
        * To schedule a campaign for immediate delivery use a <code>null</code> sendDate.
        * @param confirmationEmail An email address to send the delivery confirmation to.
        * @param sendDate The date to send the campaign at. This date should be in the clients timezone
        * @throws CreateSendException Thrown when the API responds with a HTTP Status >= 400
        * @see <a href="http://www.campaignmonitor.com/api/campaigns/#sending_a_campaign" target="_blank">
        * Sending a campaign</a>
        */
       public void send(String confirmationEmail, Date sendDate) throws CreateSendException {
           Schedule sched = new Schedule();
           sched.ConfirmationEmail = confirmationEmail;
           SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
           sched.SendDate = sendDate == null ? "Immediately" : dateFormat.format(sendDate);
    
           jerseyClient.post(String.class, sched, "campaigns", campaignID, "send.json");
       }
    

    With that it sends the time with the date by starting the campaign. Would be nice if someone could change the SimpleDateFormat in the JsonProvider I showed in my last comment.

  3. zischler commented on Aug 15, 2019

    @zischler

    @niawahyuni Maybe you could add this.

  4. zischler commented on Aug 15, 2019

    @zischler

    And here is the pull request. #49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions