aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--applets/usage.c7
-rw-r--r--coreutils/date.c108
-rw-r--r--date.c108
-rw-r--r--usage.c7
4 files changed, 100 insertions, 130 deletions
diff --git a/applets/usage.c b/applets/usage.c
index 93fbf42b9..a919a58f7 100644
--- a/applets/usage.c
+++ b/applets/usage.c
@@ -140,9 +140,10 @@ const char date_usage[] =
140 " or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n" 140 " or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
141#ifndef BB_FEATURE_TRIVIAL_HELP 141#ifndef BB_FEATURE_TRIVIAL_HELP
142 "\nDisplays the current time in the given FORMAT, or sets the system date.\n" 142 "\nDisplays the current time in the given FORMAT, or sets the system date.\n"
143 "\nOptions:\n\t-R\tOutputs RFC-822 compliant date string\n" 143 "\nOptions:\n\t-R\t\tOutputs RFC-822 compliant date string\n"
144 "\t-s\tSets time described by STRING\n" 144 "\t-d STRING\tdisplay time described by STRING, not `now'\n"
145 "\t-u\tPrints or sets Coordinated Universal Time\n" 145 "\t-s\t\tSets time described by STRING\n"
146 "\t-u\t\tPrints or sets Coordinated Universal Time\n"
146#endif 147#endif
147 ; 148 ;
148#endif 149#endif
diff --git a/coreutils/date.c b/coreutils/date.c
index a8f0d7ced..7e4216768 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -74,73 +74,57 @@ struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
74 74
75struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string) 75struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
76{ 76{
77 struct tm itm_time, jtm_time, ktm_time, ltm_time, mtm_time, ntm_time; 77 struct tm t;
78
79 itm_time = *tm_time;
80 jtm_time = *tm_time;
81 ktm_time = *tm_time;
82 ltm_time = *tm_time;
83 mtm_time = *tm_time;
84 ntm_time = *tm_time;
85 78
86 /* Parse input and assign appropriately to tm_time */ 79 /* Parse input and assign appropriately to tm_time */
87 80
88 if (sscanf(t_string, "%d:%d:%d", 81 if (t=*tm_time,sscanf(t_string, "%d:%d:%d",
89 &itm_time.tm_hour, &itm_time.tm_min, &itm_time.tm_sec) == 3) { 82 &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) {
90 83 /* no adjustments needed */
91 *tm_time = itm_time;
92 return (tm_time);
93
94 } else if (sscanf(t_string, "%d:%d",
95 &jtm_time.tm_hour, &jtm_time.tm_min) == 2) {
96
97 *tm_time = jtm_time;
98 return (tm_time);
99
100 } else if (sscanf(t_string, "%d.%d-%d:%d:%d",
101 &ktm_time.tm_mon,
102 &ktm_time.tm_mday,
103 &ktm_time.tm_hour,
104 &ktm_time.tm_min, &ktm_time.tm_sec) == 5) {
105
106 ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
107 *tm_time = ktm_time;
108 return (tm_time);
109
110 } else if (sscanf(t_string, "%d.%d-%d:%d",
111 &ltm_time.tm_mon,
112 &ltm_time.tm_mday,
113 &ltm_time.tm_hour, &ltm_time.tm_min) == 4) {
114
115 ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
116 *tm_time = ltm_time;
117 return (tm_time);
118
119 } else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
120 &mtm_time.tm_year,
121 &mtm_time.tm_mon,
122 &mtm_time.tm_mday,
123 &mtm_time.tm_hour,
124 &mtm_time.tm_min, &mtm_time.tm_sec) == 6) {
125
126 mtm_time.tm_year -= 1900; /* Adjust years */
127 mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
128 *tm_time = mtm_time;
129 return (tm_time);
130
131 } else if (sscanf(t_string, "%d.%d.%d-%d:%d",
132 &ntm_time.tm_year,
133 &ntm_time.tm_mon,
134 &ntm_time.tm_mday,
135 &ntm_time.tm_hour, &ntm_time.tm_min) == 5) {
136 ntm_time.tm_year -= 1900; /* Adjust years */
137 ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
138 *tm_time = ntm_time;
139 return (tm_time);
140 84
141 } 85 } else if (t=*tm_time,sscanf(t_string, "%d:%d",
86 &t.tm_hour, &t.tm_min) == 2) {
87 /* no adjustments needed */
88
89
90 } else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d:%d",
91 &t.tm_mon,
92 &t.tm_mday,
93 &t.tm_hour,
94 &t.tm_min, &t.tm_sec) == 5) {
95
96 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
97
98 } else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d",
99 &t.tm_mon,
100 &t.tm_mday,
101 &t.tm_hour, &t.tm_min) == 4) {
102
103 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
142 104
143 fatalError(invalid_date, t_string); 105 } else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d:%d",
106 &t.tm_year,
107 &t.tm_mon,
108 &t.tm_mday,
109 &t.tm_hour,
110 &t.tm_min, &t.tm_sec) == 6) {
111
112 t.tm_year -= 1900; /* Adjust years */
113 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
114
115 } else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d",
116 &t.tm_year,
117 &t.tm_mon,
118 &t.tm_mday,
119 &t.tm_hour, &t.tm_min) == 5) {
120 t.tm_year -= 1900; /* Adjust years */
121 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
122
123 } else {
124 fatalError(invalid_date, t_string);
125 }
126 *tm_time = t;
127 return (tm_time);
144} 128}
145 129
146 130
diff --git a/date.c b/date.c
index a8f0d7ced..7e4216768 100644
--- a/date.c
+++ b/date.c
@@ -74,73 +74,57 @@ struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
74 74
75struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string) 75struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
76{ 76{
77 struct tm itm_time, jtm_time, ktm_time, ltm_time, mtm_time, ntm_time; 77 struct tm t;
78
79 itm_time = *tm_time;
80 jtm_time = *tm_time;
81 ktm_time = *tm_time;
82 ltm_time = *tm_time;
83 mtm_time = *tm_time;
84 ntm_time = *tm_time;
85 78
86 /* Parse input and assign appropriately to tm_time */ 79 /* Parse input and assign appropriately to tm_time */
87 80
88 if (sscanf(t_string, "%d:%d:%d", 81 if (t=*tm_time,sscanf(t_string, "%d:%d:%d",
89 &itm_time.tm_hour, &itm_time.tm_min, &itm_time.tm_sec) == 3) { 82 &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) {
90 83 /* no adjustments needed */
91 *tm_time = itm_time;
92 return (tm_time);
93
94 } else if (sscanf(t_string, "%d:%d",
95 &jtm_time.tm_hour, &jtm_time.tm_min) == 2) {
96
97 *tm_time = jtm_time;
98 return (tm_time);
99
100 } else if (sscanf(t_string, "%d.%d-%d:%d:%d",
101 &ktm_time.tm_mon,
102 &ktm_time.tm_mday,
103 &ktm_time.tm_hour,
104 &ktm_time.tm_min, &ktm_time.tm_sec) == 5) {
105
106 ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
107 *tm_time = ktm_time;
108 return (tm_time);
109
110 } else if (sscanf(t_string, "%d.%d-%d:%d",
111 &ltm_time.tm_mon,
112 &ltm_time.tm_mday,
113 &ltm_time.tm_hour, &ltm_time.tm_min) == 4) {
114
115 ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
116 *tm_time = ltm_time;
117 return (tm_time);
118
119 } else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
120 &mtm_time.tm_year,
121 &mtm_time.tm_mon,
122 &mtm_time.tm_mday,
123 &mtm_time.tm_hour,
124 &mtm_time.tm_min, &mtm_time.tm_sec) == 6) {
125
126 mtm_time.tm_year -= 1900; /* Adjust years */
127 mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
128 *tm_time = mtm_time;
129 return (tm_time);
130
131 } else if (sscanf(t_string, "%d.%d.%d-%d:%d",
132 &ntm_time.tm_year,
133 &ntm_time.tm_mon,
134 &ntm_time.tm_mday,
135 &ntm_time.tm_hour, &ntm_time.tm_min) == 5) {
136 ntm_time.tm_year -= 1900; /* Adjust years */
137 ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
138 *tm_time = ntm_time;
139 return (tm_time);
140 84
141 } 85 } else if (t=*tm_time,sscanf(t_string, "%d:%d",
86 &t.tm_hour, &t.tm_min) == 2) {
87 /* no adjustments needed */
88
89
90 } else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d:%d",
91 &t.tm_mon,
92 &t.tm_mday,
93 &t.tm_hour,
94 &t.tm_min, &t.tm_sec) == 5) {
95
96 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
97
98 } else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d",
99 &t.tm_mon,
100 &t.tm_mday,
101 &t.tm_hour, &t.tm_min) == 4) {
102
103 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
142 104
143 fatalError(invalid_date, t_string); 105 } else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d:%d",
106 &t.tm_year,
107 &t.tm_mon,
108 &t.tm_mday,
109 &t.tm_hour,
110 &t.tm_min, &t.tm_sec) == 6) {
111
112 t.tm_year -= 1900; /* Adjust years */
113 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
114
115 } else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d",
116 &t.tm_year,
117 &t.tm_mon,
118 &t.tm_mday,
119 &t.tm_hour, &t.tm_min) == 5) {
120 t.tm_year -= 1900; /* Adjust years */
121 t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
122
123 } else {
124 fatalError(invalid_date, t_string);
125 }
126 *tm_time = t;
127 return (tm_time);
144} 128}
145 129
146 130
diff --git a/usage.c b/usage.c
index 93fbf42b9..a919a58f7 100644
--- a/usage.c
+++ b/usage.c
@@ -140,9 +140,10 @@ const char date_usage[] =
140 " or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n" 140 " or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
141#ifndef BB_FEATURE_TRIVIAL_HELP 141#ifndef BB_FEATURE_TRIVIAL_HELP
142 "\nDisplays the current time in the given FORMAT, or sets the system date.\n" 142 "\nDisplays the current time in the given FORMAT, or sets the system date.\n"
143 "\nOptions:\n\t-R\tOutputs RFC-822 compliant date string\n" 143 "\nOptions:\n\t-R\t\tOutputs RFC-822 compliant date string\n"
144 "\t-s\tSets time described by STRING\n" 144 "\t-d STRING\tdisplay time described by STRING, not `now'\n"
145 "\t-u\tPrints or sets Coordinated Universal Time\n" 145 "\t-s\t\tSets time described by STRING\n"
146 "\t-u\t\tPrints or sets Coordinated Universal Time\n"
146#endif 147#endif
147 ; 148 ;
148#endif 149#endif