{"id":23641249,"url":"https://github.com/tginsberg/java-timestream","last_synced_at":"2025-08-31T17:32:39.076Z","repository":{"id":57719409,"uuid":"62008423","full_name":"tginsberg/java-timestream","owner":"tginsberg","description":"A set of builders that create streams of java.time objects","archived":false,"fork":false,"pushed_at":"2018-07-04T16:31:21.000Z","size":26,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-07-26T21:54:03.333Z","etag":null,"topics":["java","java-8","java-time","stream"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tginsberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-26T21:07:07.000Z","updated_at":"2019-08-25T06:25:48.000Z","dependencies_parsed_at":"2022-08-26T10:50:32.710Z","dependency_job_id":null,"html_url":"https://github.com/tginsberg/java-timestream","commit_stats":null,"previous_names":[],"tags_count":2,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tginsberg%2Fjava-timestream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tginsberg%2Fjava-timestream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tginsberg%2Fjava-timestream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tginsberg%2Fjava-timestream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tginsberg","download_url":"https://codeload.github.com/tginsberg/java-timestream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231610640,"owners_count":18400207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","java-8","java-time","stream"],"created_at":"2024-12-28T09:58:56.681Z","updated_at":"2024-12-28T09:58:57.331Z","avatar_url":"https://github.com/tginsberg.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java-Timestream\r\nA set of builders that create streams of java.time objects. \r\n\r\nTo use this library in your project, add this to your dependencies:\r\n\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003ecom.ginsberg\u003c/groupId\u003e\r\n    \u003cartifactId\u003ejava-timestream\u003c/artifactId\u003e\r\n    \u003cversion\u003e1.1.0\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\nThese are fully functional streams, so you can use them like any other stream, once created. \r\n\r\nThe lack of a convenient `takeWhile(Predicate\u003cT\u003e predicate)` method in Java 8 is what led to the creation\r\nof this library. Now that Java 9 has `Stream.takeWhile()` support, there is no reason to add this as a dependency.\r\n   \r\nThis library can create streams of the following java.time classes:\r\n\r\n+ `LocalDate` via `LocalDateStream`\r\n+ `LocalDateTime` via `LocalDateTimeStream`\r\n+ `YearMonth` via `YearMonthStream`\r\n+ `ZonedDateTime` via `ZoneDateTimeStream`\r\n\r\nAnd has support for...\r\n\r\n+ Inclusive end point (`to`)\r\n+ Exclusive end point (`until`)\r\n+ Configurable period between stream elements (`every`)\r\n+ Streams can move forward or backward through time\r\n+ Infinite streams (by not providing an end point)\r\n\r\n## Usage\r\n\r\nEvery builder needs a non-null point in time to begin the stream. Therefore, each\r\nbuilder can be created using one of two methods:\r\n\r\n+ `.fromNow()` - Assumes 'now'\r\n+ `.from(T from)` - Type-specific starting point, provided by caller\r\n\r\nTo set the optional point in time where the stream ends (inclusive) you can call one of two methods:\r\n\r\n+ `.to(T to)` - Type-specific end point. Can be null to indicate forever\r\n+ `.to(amount, units)` - Where `amount` is a positive integer (for forward through time) or a negative integer (for backward through time), and `unit` is a valid `ChronoUnit`\r\n\r\nTo make the optional end of the stream exclusive, you can call one of two methods:\r\n\r\n+ `.until(T to)` - Type-specific end point. Can be null to indicate forever\r\n+ `.until(amount, units)` - Where `amount` is a positive integer (for forward through time) or a negative integer (for backward through time), and `unit` is a valid `ChronoUnit`\r\n\r\nTo indicate how much time should be skipped in each iteration:\r\n\r\n+ `.every(amount, units)` - Where `amount` is an integer representing the number of units, and `unit` is a valid `ChronoUnit`\r\n+ `.every(period)` - Where `period` is a valid `Period` object. (Supported on `LocalDateStream` and `YearMonthStream` only).\r\n+ `.every(duration)` - Where `duration` is a valid `Duration` object. (Supported on everything other than `LocalDateStream` and `YearMonthStream`).\r\n\r\n\r\nNote that providing an end time (via `to` or `until`) is optional. In that case, the stream will\r\nhave no end and should produce values until you stop it.\r\n\r\n## Examples\r\n\r\nCreate a stream of `LocalDateTime` objects, between now and hour from now, every two minutes:\r\n\r\n```java\r\nfinal Stream\u003cLocalDateTime\u003e stream = LocalDateTimeStream\r\n        .fromNow()\r\n        .to(1, ChronoUnit.HOURS)\r\n        .every(2, ChronoUnit.MINUTES)\r\n        .stream();\r\n```\r\n\r\nOr (equivalent):\r\n\r\n```java\r\nfinal Stream\u003cLocalDateTime\u003e stream = LocalDateTimeStream\r\n        .from(LocalDateTime.now())\r\n        .to(LocalDateTime.now().plusHours(1))\r\n        .every(2, ChronoUnit.MINUTES)\r\n        .stream();\r\n```\r\n\r\nCreate a stream of `YearMonth` objects from today, to a year ago (backward through time), stopping before the end (exclusive),\r\nevery month:\r\n\r\n```java\r\nfinal Stream\u003cYearMonth\u003e stream = YearMonthStream\r\n        .fromNow()\r\n        .until(-12, ChronoUnit.MONTHS)\r\n        .every(1, ChronoUnit.MONTHS) // This is the default\r\n        .stream();\r\n```\r\n\r\nReplace this code that does something with every minute of time over the last hour, going backwards:\r\n\r\n```java\r\nfinal LocalDateTime end = LocalDateTime.now().minusHours(1);\r\nLocalDateTime when = LocalDateTime.now();\r\n\r\nwhile(when.isAfter(end)) {\r\n    doSomething(when);\r\n    when = when.minusMinutes(1);\r\n}\r\n```\r\n\r\n... with this:\r\n\r\n```java\r\nLocalDateTimeStream\r\n    .fromNow()\r\n    .until(-1, ChronoUnit.HOURS)\r\n    .every(1, ChronoUnit.MINUTES)\r\n    .stream()\r\n    .forEach(this::doSomething);\r\n```\r\n\r\nIt's not less code, but it certainly makes it easier to understand.\r\n\r\nThere are also plenty of examples in the unit tests.\r\n\r\n## Contributing and Issues\r\n\r\nPlease feel free to file issues for change requests or bugs. If you would like to contribute new functionality, please contact me first!\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftginsberg%2Fjava-timestream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftginsberg%2Fjava-timestream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftginsberg%2Fjava-timestream/lists"}