Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add playground #41

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- "\U0001F4E6 dependencies"
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- "\U0001F4E6 dependencies"
35 changes: 35 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,41 @@ jobs:
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-pages:
runs-on: ubuntu-latest
needs: [ test ]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 8
run_install: false

- name: Install Rust and wasm-pack
run: |
rustup update stable
cargo +stable install wasm-pack

- name: Build WebAssembly module with wasm-pack
run: wasm-pack build --target bundler --out-dir ../site/pkg --release
working-directory: ./playground/wasm

- name: Build project
run: pnpm install && pnpm run build
working-directory: ./playground/site

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./playground/site/dist
publish-crate:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "duration-str"
version = "0.10.0"
version = "0.11.0"
authors = ["baoyachi <liaoymxsdl@gmail.com>"]
edition = "2021"
description = "duration string parser"
Expand All @@ -9,13 +9,14 @@ readme = "README.md"
categories = ["parsing", "date-and-time"]
repository = "https://github.com/baoyachi/duration-str"
license = "Apache-2.0"
exclude = ["./playground"]

[features]
default = ["chrono", "serde", "time"]

[dependencies]
thiserror = "1.0.37"
chrono = { version = "0.4.23", optional = true }
chrono = { version = "0.4.38", optional = true }
time = { version = "0.3.17", optional = true }

serde = { version = "1.0.147", features = ["derive"], optional = true }
Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,33 @@
[![Docs.rs](https://docs.rs/duration-str/badge.svg)](https://docs.rs/duration-str)
[![Coverage Status](https://coveralls.io/repos/github/baoyachi/duration-str/badge.svg?branch=master)](https://coveralls.io/github/baoyachi/duration-str?branch=master)

## Support
The [duration-str](https://crates.io/crates/duration-str) support multiple Duration:
* https://doc.rust-lang.org/stable/std/time/struct.Duration.html
* https://docs.rs/chrono/latest/chrono/struct.Duration.html
* https://docs.rs/time/latest/time/struct.Duration.html#

## Features:

1. Strong compatibility, accommodating leading or trailing whitespaces in strings.
2. Offers [Playground](https://baoyachi.github.io/duration-str/) support for online debugging.
3. Integrated with the [serde](https://docs.rs/serde) library.
4. Supports parsing of various `Duration` types:
* https://doc.rust-lang.org/stable/std/time/struct.Duration.html
* https://docs.rs/chrono/latest/chrono/struct.Duration.html
* https://docs.rs/time/latest/time/struct.Duration.html
5. Enables formatting of `Duration` into human-readable formats.
6. Provides precise error localization for easy troubleshooting.
7. Compatible with WebAssembly (wasm).
8. Adapts to the [humantime](https://docs.rs/humantime/latest/humantime) crate, despite its apparent lack of recent
updates...

## Notice ⚠️

The default duration unit is second.Also use below **duration unit**

## Duration Unit List

Parse string to `Duration` . The String duration unit support for one of:`["y","mon","w","d","h","m","s", "ms", "µs", "ns"]`
Parse string to `Duration` . The String duration unit support for one
of:`["y","mon","w","d","h","m","s", "ms", "µs", "ns"]`

| unit | Description | unit list option(one of) | example |
| ---- | ----------- |----------------------------------------------------------------------------------------------------| ------- |
|------|-------------|----------------------------------------------------------------------------------------------------|---------|
| y | Year | ["y" , "year" , "Y" , "YEAR" , "Year"] | 1y |
| mon | Month | ["mon" , "MON" , "Month" , "month" , "MONTH"] | 1mon |
| w | Week | ["w" , "W" , "Week" ,"WEEK" , "week"] | 1w |
Expand All @@ -34,8 +45,8 @@ Parse string to `Duration` . The String duration unit support for one of:`["y","

Also,`duration_str` support time duration simple evaluation(+,*). See example:


## example

```toml
[dependencies]
duration-str = "{latest version}"
Expand Down Expand Up @@ -82,6 +93,7 @@ fn main() {
```

## deserialize in struct

deserialize to std::time::Duration

```rust
Expand Down Expand Up @@ -123,15 +135,15 @@ struct Config {
fn main() {
let json = r#"{"time_ticker":null,"name":"foo"}"#;
let config: Config = serde_json::from_str(json).unwrap();

assert_eq!(
config,
Config {
time_ticker: None,
name: "foo".into()
}
);

let json = r#"{"name":"foo"}"#;
let config: Config = serde_json::from_str(json).unwrap();
assert_eq!(
Expand All @@ -143,6 +155,7 @@ fn main() {
);
}
```

Also you can use `deserialize_duration_chrono` or `deserialize_duration_time` function

### E.g:
Expand Down
30 changes: 30 additions & 0 deletions playground/site/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/extensions.json
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

*.tsbuildinfo
1 change: 1 addition & 0 deletions playground/site/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
5 changes: 5 additions & 0 deletions playground/site/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
19 changes: 19 additions & 0 deletions playground/site/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}
40 changes: 40 additions & 0 deletions playground/site/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "duration-str-playground",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@vueuse/core": "^10.7.0",
"core-js": "^3.8.3",
"duration-wasm": "link:./pkg",
"vue": "^3.2.13"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-service": "~5.0.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
]
}
Loading
Loading