+
+static UDate getWhen(const char *millis, const char *seconds, const char *format, const char *locale,
+ UDateFormatStyle style, const char *parse, const UChar *tz, UErrorCode *status) {
+ UDateFormat *fmt = NULL;
+ UChar uFormat[100];
+ UChar uParse[256];
+ UDate when=0;
+ int32_t parsepos = 0;
+
+ if(millis != NULL) {
+ sscanf(millis, "%lf", &when);
+ return when;
+ } else if(seconds != NULL) {
+ sscanf(seconds, "%lf", &when);
+ return when*1000.0;
+ }
+
+ if(parse!=NULL) {
+ if( format != NULL ) {
+ if(!strcmp(format,FORMAT_MILLIS)) {
+ sscanf(parse, "%lf", &when);
+ return when;
+ } else if(!strcmp(format, FORMAT_SECONDS)) {
+ sscanf(parse, "%lf", &when);
+ return when*1000.0;
+ }
+ }
+
+ fmt = udat_open(style, style, locale, tz, -1,NULL,0, status);
+ if ( format != NULL ) {
+ charsToUCharsDefault(uFormat,sizeof(uFormat)/sizeof(uFormat[0]), format,-1,status);
+ udat_applyPattern(fmt,FALSE,uFormat,-1);
+ }
+
+ charsToUCharsDefault(uParse,sizeof(uParse)/sizeof(uParse[0]), parse,-1,status);
+ when = udat_parse(fmt, uParse, -1, &parsepos, status);
+ if(U_FAILURE(*status)) {
+ fprintf(stderr, "Error in Parse: %s\n", u_errorName(*status));
+ if(parsepos > 0 && parsepos <= (int32_t)strlen(parse)) {
+ fprintf(stderr, "ERR>\"%s\" @%d\n"
+ "ERR> %*s^\n",
+ parse,parsepos,parsepos,"");
+
+ }
+ }
+
+ udat_close(fmt);
+ return when;
+ } else {
+ return ucal_getNow();
+ }
+}
+