Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39076 > unrolled thread
| Started by | cdalten@gmail.com |
|---|---|
| First post | 2019-08-07 11:47 -0700 |
| Last post | 2019-08-08 05:03 -0700 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
Evaluation strings question? cdalten@gmail.com - 2019-08-07 11:47 -0700
Re: Evaluation strings question? Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-08-07 15:10 -0400
Re: Evaluation strings question? cdalten@gmail.com - 2019-08-07 12:28 -0700
Re: Evaluation strings question? Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-08-07 15:32 -0400
Re: Evaluation strings question? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-08-07 22:05 +0200
Re: Evaluation strings question? cdalten@gmail.com - 2019-08-07 13:47 -0700
Re: Evaluation strings question? Eric Douglas <e.d.programmer@gmail.com> - 2019-08-08 05:03 -0700
| From | cdalten@gmail.com |
|---|---|
| Date | 2019-08-07 11:47 -0700 |
| Subject | Evaluation strings question? |
| Message-ID | <868b9ba4-bc72-4ad4-8a13-a91bd1ae9c2e@googlegroups.com> |
Given a method like the following...
@TargetApi(24)
public void convertEndCivilianTimeToMilitaryTime(String endHour, String endMinute, String endAmOrPm) {
if (endAmOrPm.equals("PM") && !endHour.equals("12")) {
endMilitaryHour = Integer.parseInt(endHour) + 12;
endMilitaryMinute = Integer.parseInt(endMinute);
//setStartMilitaryHour(startMilitaryHour);
//setStartMilitaryMinute(Integer.parseInt(startMinute));
} else if (endAmOrPm.equals("AM") && endHour.equals("12")) {
endMilitaryHour = 24;
endMilitaryMinute = Integer.parseInt(endMinute);
}
else {
try {
endMilitaryHour = Integer.parseInt(endHour);
endMilitaryMinute = Integer.parseInt(endMinute);
} catch (Exception e) {
Log.e("LG_WORK_PHONE", "BLANK: " + e);
}
}
}
This part..
if (endAmOrPm.equals("PM") && !endHour.equals("12")) {
}
evaluates TRUE when I run the program program but evaluates FALSE when I test it on my IDE evaluate code screen. Can someone point me in the right direction as to why the strings display this kind of behavior? Because I have no clue why it does what it does.
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2019-08-07 15:10 -0400 |
| Message-ID | <qif7ns$ll7$1@dont-email.me> |
| In reply to | #39076 |
On 8/7/2019 2:47 PM, cdalten@gmail.com wrote:
> Given a method like the following...
>
> @TargetApi(24)
> public void convertEndCivilianTimeToMilitaryTime(String endHour, String endMinute, String endAmOrPm) {
> [... see up-thread ...]
>
> This part..
>
> if (endAmOrPm.equals("PM") && !endHour.equals("12")) {
>
> }
>
> evaluates TRUE when I run the program program but evaluates FALSE when I test it on my IDE evaluate code screen. Can someone point me in the right direction as to why the strings display this kind of behavior? Because I have no clue why it does what it does.
I have no clue, either, but it would be extremely useful to know
exactly what the input strings look like. Print them with start and
end markers of some kind, so you can detect extraneous white space
and the like:
System.out.println("endHour = [" + endHour + "]");
System.out.println("endMinute = [" + endMinute + "]");
System.out.println("endAmOrPm = [" + endAmOrPm + "]");
// ... or use your favorite logging framework ...
As a side observation, I sort of wonder whether the guts of this
method might do better to use java.text.SimpleDateFormat. (I'm not
an Android developer, so maybe my ignorance is showing -- but if
SimpleDateFormat is available, it seems like it could be made to
do most of the work for you.)
--
esosman@comcast-dot-net.invalid
Five hundred thirty-two days to go.
[toc] | [prev] | [next] | [standalone]
| From | cdalten@gmail.com |
|---|---|
| Date | 2019-08-07 12:28 -0700 |
| Message-ID | <06eded37-b72d-42a4-82f1-87e2d53a2252@googlegroups.com> |
| In reply to | #39077 |
The input strings are being fed in by an ugly method that is proprietary to my platform.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2019-08-07 15:32 -0400 |
| Message-ID | <qif918$u6h$1@dont-email.me> |
| In reply to | #39078 |
On 8/7/2019 3:28 PM, cdalten@gmail.com wrote:
> The input strings are being fed in by an ugly method that is proprietary to my platform.
Are you 100% sure they're of the expected form? That is,
have you examined them *as received* from the ugly feeder?
(And I can't see why SimpleDateFormat would care about the
Strings' provenance; a String is a String is a String.)
--
esosman@comcast-dot-net.invalid
Five hundred thirty-two days to go.
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2019-08-07 22:05 +0200 |
| Message-ID | <qifaul$8om$1@dont-email.me> |
| In reply to | #39078 |
On 2019-08-07 21:28, cdalten@gmail.com wrote: > The input strings are being fed in by an ugly method that is proprietary to my platform. You seem to have a logger at your disposal. So log them. Most likely the input is different between your program run and the in-IDE execution. -- DF.
[toc] | [prev] | [next] | [standalone]
| From | cdalten@gmail.com |
|---|---|
| Date | 2019-08-07 13:47 -0700 |
| Message-ID | <a4344d5f-edca-4545-8dbf-87c6cebe2648@googlegroups.com> |
| In reply to | #39080 |
I'll look into some more in the morning.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2019-08-08 05:03 -0700 |
| Message-ID | <f1dda7ff-e0d3-4987-bc1b-efdd8f7c5b35@googlegroups.com> |
| In reply to | #39077 |
On Wednesday, August 7, 2019 at 3:11:02 PM UTC-4, Eric Sosman wrote:
> I have no clue, either, but it would be extremely useful to know
> exactly what the input strings look like. Print them with start and
> end markers of some kind, so you can detect extraneous white space
> and the like:
>
> System.out.println("endHour = [" + endHour + "]");
> System.out.println("endMinute = [" + endMinute + "]");
> System.out.println("endAmOrPm = [" + endAmOrPm + "]");
> // ... or use your favorite logging framework ...
>
Start and end markers are always helpful for displaying strings if you just need to know if there's spaces before or after. If there's any chance there's unprintable characters you'll have to convert to hex.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web