Skip to content

Commit

Permalink
Merge pull request #9 from kaicoh/release/v0.3.1
Browse files Browse the repository at this point in the history
v0.3.1
  • Loading branch information
kaicoh committed Apr 9, 2024
2 parents 7bc49b6 + ee1320d commit 0f83fc0
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 201 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.3.1][] - 2024-04-10

- https://github.com/kaicoh/slack-messaging/pull/10 Improve date formatting.

## [0.3.0][] - 2024-04-09

- https://github.com/kaicoh/slack-messaging/pull/8 Builder pattern.
Expand All @@ -22,6 +26,7 @@

- pre-release

[0.3.1]: https://github.com/kaicoh/slack-messaging/releases/v0.3.1
[0.3.0]: https://github.com/kaicoh/slack-messaging/releases/v0.3.0
[0.2.2]: https://github.com/kaicoh/slack-messaging/releases/v0.2.2
[0.2.1]: https://github.com/kaicoh/slack-messaging/releases/v0.2.1
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slack-messaging"
version = "0.3.0"
version = "0.3.1"
authors = ["kaicoh <[email protected]>"]
edition = "2021"
keywords = ["slack", "messaging", "webhook"]
Expand All @@ -15,7 +15,8 @@ all-features = true

[dependencies]
chrono = { version = "0.4", optional = true }
regex = { version = "1.7", optional = true }
once_cell = { version = "1.19", optional = true }
regex = { version = "1.10", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

Expand All @@ -24,4 +25,4 @@ reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }

[features]
fmt = ["dep:chrono", "dep:regex"]
fmt = ["dep:chrono", "dep:once_cell", "dep:regex"]
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,37 @@ Enable `fmt` module and format messages in [this way](https://api.slack.com/refe

```rust
use chrono::prelude::*;
use slack_messaging::fmt::DateFormat;
use slack_messaging::fmt::DateFormatter;

// Formatter without optional link.
let f = DateFormatter::builder()
.token("{date_short} at {time}")
.build();

let dt = DateTime::parse_from_rfc3339("2023-02-27T12:34:56+09:00").unwrap();
let f = DateFormat::new(dt).token("{date_short} at {time}");

assert_eq!(
format!("{f}"),
f.format(&dt),
"<!date^1677468896^{date_short} at {time}|Feb 27, 2023 at 12:34 PM>"
);

// You can also set optional link when formatting.
assert_eq!(
f.format_with_link(&dt, "https://example.com"),
"<!date^1677468896^{date_short} at {time}^https://example.com|Feb 27, 2023 at 12:34 PM>"
);

// Formatter with optional link.
let f = DateFormatter::builder()
.token("{date_short} at {time}")
.link("https://example.com")
.build();

// This time, format method returns text with link set to the formatter.
assert_eq!(
f.format(&dt),
"<!date^1677468896^{date_short} at {time}^https://example.com|Feb 27, 2023 at 12:34 PM>"
);
```

## License
Expand Down
Loading

0 comments on commit 0f83fc0

Please sign in to comment.