Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendDate ignores hour #40

Open
tm13 opened this issue Jan 31, 2018 · 4 comments
Open

sendDate ignores hour #40

tm13 opened this issue Jan 31, 2018 · 4 comments

Comments

@tm13
Copy link

tm13 commented Jan 31, 2018

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.

@zischler
Copy link

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);
        }
    };

@zischler
Copy link

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.

@zischler
Copy link

@niawahyuni Maybe you could add this.

@zischler
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants