Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35561
| From | Tassilo Horn <tsdh@gnu.org> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Parsing calendar weeks to LocalDates with DateTimeFormatter |
| Date | 2016-09-07 10:11 +0200 |
| Organization | University Koblenz-Landau Campus Koblenz |
| Message-ID | <87eg4wgmcw.fsf@gnu.org> (permalink) |
| References | <87inu8gpqv.fsf@gnu.org> |
Tassilo Horn <tsdh@gnu.org> writes:
> // When parsing calendar weeks like "22.2016", we want to get
> // the last work day in that week. We assume that everyone
> // in every locale has a 5 days work week (don't know how to do
> // better).
> return FORMATTER_KW.parse(editorText, temporal ->
> {
> WeekFields weekFields = WeekFields.of(Locale.getDefault());
> DayOfWeek firstDayInWeek = weekFields.getFirstDayOfWeek();
> DayOfWeek lastWorkDay = firstDayInWeek.minus(4);
> long weekOfWeekBasedYear = temporal.getLong(weekFields.weekOfWeekBasedYear());
> long year = temporal.getLong(weekFields.weekBasedYear());
> LocalDate date = LocalDate.of(0, 1, 1);
> date = date.plusYears(year);
> date = date.plusWeeks(weekOfWeekBasedYear);
> date = date.with(lastWorkDay);
> return date;
> });
Oh, obviously StartOfWeek - 4 days is not a sane assumption for last
workday, and neither would be StartOfWeek + 4. So right now, I just use
DayOfWeek.FRIDAY.
Bye,
Tassilo
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Parsing calendar weeks to LocalDates with DateTimeFormatter Tassilo Horn <tsdh@gnu.org> - 2016-09-07 08:58 +0200
Re: Parsing calendar weeks to LocalDates with DateTimeFormatter Tassilo Horn <tsdh@gnu.org> - 2016-09-07 10:11 +0200
Re: Parsing calendar weeks to LocalDates with DateTimeFormatter Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-09-09 22:46 +0100
Re: Parsing calendar weeks to LocalDates with DateTimeFormatter Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-09-11 16:43 +0100
Re: Parsing calendar weeks to LocalDates with DateTimeFormatter Lew <lewbloch@gmail.com> - 2016-09-13 17:50 -0700
Re: Parsing calendar weeks to LocalDates with DateTimeFormatter Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-09-17 19:34 +0100
Re: Parsing calendar weeks to LocalDates with DateTimeFormatter Tassilo Horn <tsdh@gnu.org> - 2016-09-12 09:18 +0200
Re: Parsing calendar weeks to LocalDates with DateTimeFormatter Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-09-13 23:39 +0100
csiph-web