Hi, all!
i am use the xml-rpc service in my the java application. I am do update/insert of the nod. I am use the node.save method. All fields has been changed/inserted. But the value of the timstamp field not changed. After update/insert the timestamp field is empty. I do not get the error. I am not understand - why? How i can solved it problem?
Code on java:
java.util.Date date = new java.util.Date(fieldValue[i]);
valueMap.put("value", (date.getTime()/1000));
} catch(Exception ex){
valueMap.put("value", (Long.valueOf(timestamp)));
}
valueMap = new HashMap();
valueMap.put("timezone", "America/New_York");
valueMap.put("timezone_db", "UTC");
valueMap.put("date_type", "datestamp");
valueArray[0] = valueMap;
newNode.put(fieldName[i], valueArray);
Thanks!

Comments

rusbob’s picture

Thanks! I solved problem.

joe.murray’s picture

It's useful to post solutions to problems you've had so that others can benefit.

Cheers,
Joe

Joe

ray007’s picture

any chance you're gonna share your solution with us?

rusbob’s picture

My solving:
Map valueMap = new HashMap();
Map datatimeMap = new HashMap();
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
try {
gc.setTime(df.parse(fieldValue[i]));
} catch (Exception ex) {
}
datatimeMap.put("date", gc.get(Calendar.MONTH)+"/"
+gc.get(Calendar.DATE)+"/"+ gc.get(Calendar.YEAR));
datatimeMap.put("time", gc.get(Calendar.HOUR)+":"
+gc.get(Calendar.MINUTE)+":"+ gc.get(Calendar.SECOND));
valueMap.put("value",datatimeMap);
Object[] valueArray = {valueMap};
newNode.put(fieldName[i], valueArray);

Work fine!

cizar’s picture

I was looking the solution for the same problem. Here is my solution in PHP. The 'value' of $field_date[0] must correspond to the widget type and the input format. In my case I used the widget "Text Field with custom input format" and the input format "Y-m-d H:i:s".


require 'Zend/XmlRpc/Client.php';

$xmlrpc_url = 'http://drupal.local/services/xmlrpc';
$user = 'admin';
$pass = '123456';

try
{
  $client = new Zend_XmlRpc_Client($xmlrpc_url);
  
  $result = $client->call('system.connect');
  $sessid = $result['sessid'];
  
  $result = $client->call('user.login', array($sessid, $user, $pass));
  $sessid = $result['sessid'];
  $user   = $result['user'];
  
  $date = strtotime('May 25th, 2010');
  
  $node = array(
    'title'      => 'Testing',
    'type'       => 'story',
    'uid'        => $user['uid'],
    'field_date' => array(array('value' => array('date' => date('Y-m-d H:i:s', $date))))
  );
  
  echo $client->call('node.save', array($sessid, $node));
  echo "\n" . date('Y-m-d H:i:s', $date);
}
catch (Exception $ex)
{
    echo get_class($ex) . "\n" . $ex->getMessage();
}

m3n0R’s picture

rusbob you say work fine, but I think there are some fields you have not mentioned, like :

fieldValue[i]
df --> what's df? gc.setTime(df.parse(fieldValue[i]));

I'm doing that... :

public void setTime(String o) {		
		
		Date date = new Date();
		Object[] array = new Object[1];
		HashMap<String, Object> myHashMap = new HashMap<String, Object>();
		Map datatimeMap = new HashMap();
		GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
		//gc.setTime(date);
		//Log.v(null,gc.get(Calendar.YEAR)+"-"+gc.get(Calendar.MONTH)+"-"+ gc.get(Calendar.DATE) + gc.get(Calendar.HOUR)+":"+gc.get(Calendar.MINUTE)+":"+ gc.get(Calendar.SECOND));
		datatimeMap.put("date", "2010-10-24");
		datatimeMap.put("time", "12:00");
		//myHashMap.put("value","25/09/2010 12:00");I can't do it with string
		 myHashMap.put("value",datatimeMap);
		array[0] = myHashMap;   	
		put(TIME, array);
	}

and I always get the same two errors..

 09-23 10:28:39.906: WARN/System.err(350): org.xmlrpc.android.XMLRPCFault: XMLRPC Fault: There are errors in Time:The dates are invalid.
or
09-25 12:36:41.397: WARN/System.err(527): org.xmlrpc.android.XMLRPCFault: XMLRPC Fault: time From date is invalid. [code 1]

I think it depends your drupal site configuration, no?