Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
3251378e
E
Exa
项目概览
vnotepad
/
Exa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
Exa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3251378e
编写于
7月 06, 2017
作者:
B
Benjamin Sago
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add iso time style
上级
f0eed9fd
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
62 addition
and
3 deletion
+62
-3
src/options/view.rs
src/options/view.rs
+4
-3
src/output/time.rs
src/output/time.rs
+54
-0
xtests/dates_iso
xtests/dates_iso
+3
-0
xtests/run.sh
xtests/run.sh
+1
-0
未找到文件。
src/options/view.rs
浏览文件 @
3251378e
...
@@ -240,15 +240,16 @@ impl TimeFormat {
...
@@ -240,15 +240,16 @@ impl TimeFormat {
/// Determine how time should be formatted in timestamp columns.
/// Determine how time should be formatted in timestamp columns.
fn
deduce
(
matches
:
&
getopts
::
Matches
)
->
Result
<
TimeFormat
,
Misfire
>
{
fn
deduce
(
matches
:
&
getopts
::
Matches
)
->
Result
<
TimeFormat
,
Misfire
>
{
pub
use
output
::
time
::{
DefaultFormat
};
pub
use
output
::
time
::{
DefaultFormat
,
ISOFormat
};
const
STYLES
:
&
[
&
str
]
=
&
[
"default"
,
"long-iso"
,
"full-iso"
];
const
STYLES
:
&
[
&
str
]
=
&
[
"default"
,
"long-iso"
,
"full-iso"
,
"iso"
];
if
let
Some
(
word
)
=
matches
.opt_str
(
"time-style"
)
{
if
let
Some
(
word
)
=
matches
.opt_str
(
"time-style"
)
{
match
&*
word
{
match
&*
word
{
"default"
=>
Ok
(
TimeFormat
::
DefaultFormat
(
DefaultFormat
::
new
())),
"default"
=>
Ok
(
TimeFormat
::
DefaultFormat
(
DefaultFormat
::
new
())),
"iso"
=>
Ok
(
TimeFormat
::
ISOFormat
(
ISOFormat
::
new
())),
"long-iso"
=>
Ok
(
TimeFormat
::
LongISO
),
"long-iso"
=>
Ok
(
TimeFormat
::
LongISO
),
"full-iso"
=>
Ok
(
TimeFormat
::
FullISO
),
"full-iso"
=>
Ok
(
TimeFormat
::
FullISO
),
otherwise
=>
Err
(
Misfire
::
bad_argument
(
"time-style"
,
otherwise
,
STYLES
))
otherwise
=>
Err
(
Misfire
::
bad_argument
(
"time-style"
,
otherwise
,
STYLES
))
,
}
}
}
}
else
{
else
{
...
...
src/output/time.rs
浏览文件 @
3251378e
...
@@ -7,6 +7,7 @@ use fs::fields::Time;
...
@@ -7,6 +7,7 @@ use fs::fields::Time;
pub
enum
TimeFormat
{
pub
enum
TimeFormat
{
DefaultFormat
(
DefaultFormat
),
DefaultFormat
(
DefaultFormat
),
ISOFormat
(
ISOFormat
),
LongISO
,
LongISO
,
FullISO
,
FullISO
,
}
}
...
@@ -15,6 +16,7 @@ impl TimeFormat {
...
@@ -15,6 +16,7 @@ impl TimeFormat {
pub
fn
format_local
(
&
self
,
time
:
Time
)
->
String
{
pub
fn
format_local
(
&
self
,
time
:
Time
)
->
String
{
match
*
self
{
match
*
self
{
TimeFormat
::
DefaultFormat
(
ref
fmt
)
=>
fmt
.format_local
(
time
),
TimeFormat
::
DefaultFormat
(
ref
fmt
)
=>
fmt
.format_local
(
time
),
TimeFormat
::
ISOFormat
(
ref
iso
)
=>
iso
.format_local
(
time
),
TimeFormat
::
LongISO
=>
long_local
(
time
),
TimeFormat
::
LongISO
=>
long_local
(
time
),
TimeFormat
::
FullISO
=>
full_local
(
time
),
TimeFormat
::
FullISO
=>
full_local
(
time
),
}
}
...
@@ -23,6 +25,7 @@ impl TimeFormat {
...
@@ -23,6 +25,7 @@ impl TimeFormat {
pub
fn
format_zoned
(
&
self
,
time
:
Time
,
zone
:
&
TimeZone
)
->
String
{
pub
fn
format_zoned
(
&
self
,
time
:
Time
,
zone
:
&
TimeZone
)
->
String
{
match
*
self
{
match
*
self
{
TimeFormat
::
DefaultFormat
(
ref
fmt
)
=>
fmt
.format_zoned
(
time
,
zone
),
TimeFormat
::
DefaultFormat
(
ref
fmt
)
=>
fmt
.format_zoned
(
time
,
zone
),
TimeFormat
::
ISOFormat
(
ref
iso
)
=>
iso
.format_zoned
(
time
,
zone
),
TimeFormat
::
LongISO
=>
long_zoned
(
time
,
zone
),
TimeFormat
::
LongISO
=>
long_zoned
(
time
,
zone
),
TimeFormat
::
FullISO
=>
full_zoned
(
time
,
zone
),
TimeFormat
::
FullISO
=>
full_zoned
(
time
,
zone
),
}
}
...
@@ -141,3 +144,54 @@ fn full_zoned(time: Time, zone: &TimeZone) -> String {
...
@@ -141,3 +144,54 @@ fn full_zoned(time: Time, zone: &TimeZone) -> String {
date
.hour
(),
date
.minute
(),
date
.second
(),
time
.nanoseconds
,
date
.hour
(),
date
.minute
(),
date
.second
(),
time
.nanoseconds
,
offset
.hours
(),
offset
.minutes
()
.abs
())
offset
.hours
(),
offset
.minutes
()
.abs
())
}
}
#[derive(Debug,
Clone)]
pub
struct
ISOFormat
{
/// The year of the current time. This gets used to determine which date
/// format to use.
pub
current_year
:
i64
,
}
impl
ISOFormat
{
pub
fn
new
()
->
Self
{
let
current_year
=
LocalDateTime
::
now
()
.year
();
ISOFormat
{
current_year
}
}
fn
is_recent
(
&
self
,
date
:
LocalDateTime
)
->
bool
{
date
.year
()
==
self
.current_year
}
#[allow(trivial_numeric_casts)]
fn
format_local
(
&
self
,
time
:
Time
)
->
String
{
let
date
=
LocalDateTime
::
at
(
time
.seconds
as
i64
);
if
self
.is_recent
(
date
)
{
format!
(
"{:04}-{:02}-{:02}"
,
date
.year
(),
date
.month
()
as
usize
,
date
.day
())
}
else
{
format!
(
"{:02}-{:02} {:02}:{:02}"
,
date
.month
()
as
usize
,
date
.day
(),
date
.hour
(),
date
.minute
())
}
}
#[allow(trivial_numeric_casts)]
fn
format_zoned
(
&
self
,
time
:
Time
,
zone
:
&
TimeZone
)
->
String
{
let
date
=
zone
.to_zoned
(
LocalDateTime
::
at
(
time
.seconds
as
i64
));
if
self
.is_recent
(
date
)
{
format!
(
"{:04}-{:02}-{:02}"
,
date
.year
(),
date
.month
()
as
usize
,
date
.day
())
}
else
{
format!
(
"{:02}-{:02} {:02}:{:02}"
,
date
.month
()
as
usize
,
date
.day
(),
date
.hour
(),
date
.minute
())
}
}
}
xtests/dates_iso
0 → 100644
浏览文件 @
3251378e
.[1;33mr[31mw[0m[38;5;244m-[33mr[31mw[38;5;244m-[33mr[38;5;244m--[0m [1;32m0[0m cassowary [34m06-15 23:14[0m peach
.[1;33mr[31mw[0m[38;5;244m-[33mr[31mw[38;5;244m-[33mr[38;5;244m--[0m [1;32m0[0m cassowary [34m03-03 00:00[0m pear
.[1;33mr[31mw[0m[38;5;244m-[33mr[31mw[38;5;244m-[33mr[38;5;244m--[0m [1;32m0[0m cassowary [34m07-22 10:38[0m plum
xtests/run.sh
浏览文件 @
3251378e
...
@@ -112,6 +112,7 @@ $exa $testcases/dates -lh --accessed --sort=accessed 2>&1 | diff -q - $results/d
...
@@ -112,6 +112,7 @@ $exa $testcases/dates -lh --accessed --sort=accessed 2>&1 | diff -q - $results/d
$exa
$testcases
/dates
-lh
--sort
=
modified 2>&1 | diff
-q
-
$results
/dates_modified
||
exit
1
$exa
$testcases
/dates
-lh
--sort
=
modified 2>&1 | diff
-q
-
$results
/dates_modified
||
exit
1
$exa
$testcases
/dates
-l
--time-style
=
long-iso 2>&1 | diff
-q
-
$results
/dates_long_iso
||
exit
1
$exa
$testcases
/dates
-l
--time-style
=
long-iso 2>&1 | diff
-q
-
$results
/dates_long_iso
||
exit
1
$exa
$testcases
/dates
-l
--time-style
=
full-iso 2>&1 | diff
-q
-
$results
/dates_full_iso
||
exit
1
$exa
$testcases
/dates
-l
--time-style
=
full-iso 2>&1 | diff
-q
-
$results
/dates_full_iso
||
exit
1
$exa
$testcases
/dates
-l
--time-style
=
iso 2>&1 | diff
-q
-
$results
/dates_iso
||
exit
1
# Paths and directories
# Paths and directories
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录