Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35561
| Path | csiph.com!news.mixmin.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!cache.uni-koblenz.de!not-for-mail |
|---|---|
| From | Tassilo Horn <tsdh@gnu.org> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Parsing calendar weeks to LocalDates with DateTimeFormatter |
| Date | Wed, 07 Sep 2016 10:11:59 +0200 |
| Organization | University Koblenz-Landau Campus Koblenz |
| Lines | 26 |
| Message-ID | <87eg4wgmcw.fsf@gnu.org> (permalink) |
| References | <87inu8gpqv.fsf@gnu.org> |
| NNTP-Posting-Host | j289989.servers.jiffybox.net |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| X-Trace | cache.uni-koblenz.de 1473235919 28563 134.119.24.195 (7 Sep 2016 08:11:59 GMT) |
| X-Complaints-To | news@cache.uni-koblenz.de |
| NNTP-Posting-Date | Wed, 7 Sep 2016 08:11:59 +0000 (UTC) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
| Cancel-Lock | sha1:yd1ysoTR4eT9oCC6e44BBlJotIA= |
| Xref | csiph.com comp.lang.java.programmer:35561 |
Show key headers only | View raw
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