tm_wday = k;
- f = 1;
- }
- }
-
- if (!f)
- return (char*) &s[i];
-
- break;
-
- default:
- break;
+ break;
+
+ /* The abbreviated or full month name. */
+ case 'b':
+ case 'B':
+ ptr = (fd == 'b') ? (char **)jalali_months_3 : (char **)jalali_months;
+ f = 0;
+
+ for (k = 0; k < J_YEAR_LENGTH_IN_MONTHS; k++) {
+ if (!strcasecmp(buf, ptr[k])) {
+ jtm->tm_mon = k;
+ f = 1;
+ }
+ }
+
+ if (!f)
+ return (char *)&s[i];
+
+ break;
+
+ /* The day of the month as a decimal number (range 01 to 31). */
+ case 'd':
+ case 'e':
+ jtm->tm_mday = atoi(buf);
+ break;
+
+ /*
+ * The hour as a decimal number using a 24-hour clock
+ * (range 00 to 23).
+ */
+ case 'H':
+ jtm->tm_hour = atoi(buf);
+ break;
+
+ /* The day of the year as a decimal number (range 001 to 366). */
+ case 'j':
+ jtm->tm_yday = atoi(buf) - 1;
+ break;
+
+ /* The month as a decimal number (range 01 to 12). */
+ case 'm':
+ jtm->tm_mon = atoi(buf) - 1;
+ break;
+
+ /* The minute as a decimal number (range 00 to 59). */
+ case 'M':
+ jtm->tm_min = atoi(buf);
+ break;
+
+ /* Seconds since epoch. (1970/1/1) */
+ case 's':
+ t = (time_t)atol(buf);
+ jlocaltime_r(&t, &_j);
+ memcpy(jtm, &_j, sizeof(struct jtm));
+ break;
+
+ /* The second as a decimal number (range 00 to 59). */
+ case 'S':
+ jtm->tm_sec = atoi(buf);
+ break;
+
+ /*
+ * The year as a decimal number without a century
+ * (range 00 to 99).
+ */
+ case 'y':
+ tmp = atoi(buf);
+ if (tmp >= 19 && tmp < 100)
+ jtm->tm_year = 1300 + tmp;
+ else
+ jtm->tm_year = 1400 + tmp;
+ break;
+
+ /* The year as a decimal number including the century. */
+ case 'Y':
+ jtm->tm_year = atoi(buf);
+ break;
+
+ /* The abbreviated or full weekday name. (Farsi) */
+ case 'q':
+ case 'h':
+ ptr = (fd == 'h') ? (char **)jalali_days_3_fa : (char **)jalali_days_fa;
+ f = 0;
+
+ for (k = 0; k < J_WEEK_LENGTH; k++) {
+ if (!strcasecmp(buf, ptr[k])) {
+ jtm->tm_wday = k;
+ f = 1;
}
+ }
+ if (!f)
+ return (char *)&s[i];
- c++;
- j += diff + 2;
- i += diff1 + diff;
+ break;
+
+ default:
+ break;
}
- return (char*) &s[s_s];
+ c++;
+ j += diff + 2;
+ i += diff1 + diff;
+ }
+
+ return (char *)&s[s_s];
}
-char* jasctime_r(const struct jtm* jtm, char* buf)
-{
- if (!jtm || !buf)
- return 0;
+char *jasctime_r(const struct jtm *jtm, char *buf) {
+ if (!jtm || !buf)
+ return 0;
- in_jasctime(jtm, buf);
+ in_jasctime(jtm, buf);
- return buf;
+ return buf;
}
-struct jtm* jlocaltime_r(const time_t* timep, struct jtm* result)
-{
- if (!timep || !result)
- return 0;
+struct jtm *jlocaltime_r(const time_t *timep, struct jtm *result) {
+ if (!timep || !result)
+ return 0;
- in_jlocaltime(timep, result);
+ in_jlocaltime(timep, result);
- return result;
+ return result;
}
-struct jtm* jgmtime_r(const time_t* timep, struct jtm* result)
-{
- if (!timep || !result)
- return 0;
+struct jtm *jgmtime_r(const time_t *timep, struct jtm *result) {
+ if (!timep || !result)
+ return 0;
- in_jgmtime(timep, result);
+ in_jgmtime(timep, result);
- return result;
+ return result;
}
-char* jctime_r(const time_t* timep, char* buf)
-{
- if (!timep || !buf)
- return 0;
+char *jctime_r(const time_t *timep, char *buf) {
+ if (!timep || !buf)
+ return 0;
- in_jctime(timep, buf);
+ in_jctime(timep, buf);
- return buf;
+ return buf;
}
/*
@@ -884,41 +853,38 @@ char* jctime_r(const time_t* timep, char* buf)
* jalali_to_farsi() converts an integer's digits to Arabic-Indic
* padding works just like printf() field width.
*/
-int jalali_to_farsi(char* buf,
- size_t n,
- int padding,
- char* pad,
- int d)
-{
- char _buf[100] = {0};
- int i=0, j=0;
- int p = 0;
- int c = 0;
- int cw = (pad[0] < 0) ? 2 : 1;
-
- for (i=d; i!=0; c++,
- _buf[p] = farsi_digits[i%10 > 0 ? i%10 : -(i%10)][1],
- _buf[p+1] = farsi_digits[i%10 > 0 ? i%10 : -(i%10)][0],
- i/=10,
- p+=2);
-
- if (d < 0) {
- _buf[p] = '-';
- c++;
- p++;
- }
-
- _buf[p]= 0;
- buf[0] = 0;
- i=0;
-
- for (i=0; (i<(padding - c)) && (i*cw < (int)(n-1));
- strcat(buf, pad), i++);
- buf[i*cw] = 0;
-
- for (j=0, i*=cw; (j 0 ? i % 10 : -(i % 10)][1],
+ _buf[p + 1] = farsi_digits[i % 10 > 0 ? i % 10 : -(i % 10)][0], i /= 10,
+ p += 2)
+ ;
+
+ if (d < 0) {
+ _buf[p] = '-';
+ c++;
+ p++;
+ }
+
+ _buf[p] = 0;
+ buf[0] = 0;
+ i = 0;
+
+ for (i = 0; (i < (padding - c)) && (i * cw < (int)(n - 1));
+ strcat(buf, pad), i++)
+ ;
+ buf[i * cw] = 0;
+
+ for (j = 0, i *= cw; (j < p) && (i < (int)(n - 1));
+ buf[i] = _buf[p - j - 1], i++, j++)
+ ;
+ buf[i] = 0;
+
+ return i;
}
diff --git a/sources/libjalali/jtime.h b/sources/libjalali/jtime.h
index fd658f1..6f8baaf 100644
--- a/sources/libjalali/jtime.h
+++ b/sources/libjalali/jtime.h
@@ -31,30 +31,30 @@ extern "C" {
#define MAX_BUF_SIZE 2048
-extern char* jasctime(const struct jtm* jtm);
+extern char *jasctime(const struct jtm *jtm);
-extern char* jctime(const time_t* timep);
+extern char *jctime(const time_t *timep);
-extern struct jtm* jgmtime(const time_t* timep);
+extern struct jtm *jgmtime(const time_t *timep);
-extern struct jtm* jlocaltime(const time_t* timep);
+extern struct jtm *jlocaltime(const time_t *timep);
-extern time_t jmktime(struct jtm* jtm);
+extern time_t jmktime(struct jtm *jtm);
-extern size_t jstrftime(char* s, size_t max, const char* format,
- const struct jtm* jtm);
+extern size_t jstrftime(char *s, size_t max, const char *format,
+ const struct jtm *jtm);
-extern char* jstrptime(const char* s, const char* format, struct jtm* jtm);
+extern char *jstrptime(const char *s, const char *format, struct jtm *jtm);
-extern char* jasctime_r(const struct jtm* jtm, char* buf);
+extern char *jasctime_r(const struct jtm *jtm, char *buf);
-extern char* jctime_r(const time_t* timep, char* buf);
+extern char *jctime_r(const time_t *timep, char *buf);
-extern struct jtm* jgmtime_r(const time_t* timep, struct jtm* result);
+extern struct jtm *jgmtime_r(const time_t *timep, struct jtm *result);
-extern struct jtm* jlocaltime_r(const time_t* timep, struct jtm* result);
+extern struct jtm *jlocaltime_r(const time_t *timep, struct jtm *result);
-extern int jalali_to_farsi(char* buf, size_t n, int padding, char* pad, int d);
+extern int jalali_to_farsi(char *buf, size_t n, int padding, char *pad, int d);
#ifdef __cplusplus
}