From 598090797c2cb3a4fe945d2eacd3eca42a0cfe5d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 31 May 2020 01:15:36 +1200 Subject: First version from tejr dotfiles v9.12.0 --- README.md | 27 +++++++++++++++++++++++++++ VERSION | 1 + autoload/put_date.vim | 24 ++++++++++++++++++++++++ doc/put_date.txt | 44 ++++++++++++++++++++++++++++++++++++++++++++ plugin/put_date.vim | 6 ++++++ 5 files changed, 102 insertions(+) create mode 100644 README.md create mode 100644 VERSION create mode 100644 autoload/put_date.vim create mode 100644 doc/put_date.txt create mode 100644 plugin/put_date.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..469b518 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +put\_date.vim +============= + +This plugin provides a convenience wrapper around `strftime()` to insert the +current date and time in the buffer, defaulting to RFC2822 format, and +requiring neither percent signs nor quoting for any specified format. + + :PutDate + Sun, 31 May 2020 01:04:41 +1200 + :PutDate d/m/Y + 31/05/2020 + +An attempt to use the UTC time zone rather than the local time zone is made if +a bang is added: + + :PutDate! + Sat, 30 May 2020 13:04:14 +0000 + :PutDate! + 13 + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/autoload/put_date.vim b/autoload/put_date.vim new file mode 100644 index 0000000..b0b0b54 --- /dev/null +++ b/autoload/put_date.vim @@ -0,0 +1,24 @@ +" RFC2822 format string for strftime() +let s:rfc_2822 = '%a, %d %b %Y %T %z' + +" Write a date to the buffer, UTC or local, in the specified format, +" defaulting to RFC2822; formats are provided without the leading % signs +" before each letter, like PHP date() +" +function! put_date#(line, utc, format) abort + let line = a:line + let utc = a:utc + let format = strlen(a:format) + \ ? substitute(a:format, '\a', '%&', 'g') + \ : s:rfc_2822 + if utc + if exists('$TZ') + let tz = $TZ + endif + let $TZ = 'UTC' + endif + execute line.'put =strftime(format)' + if exists('tz') + let $TZ = tz + endif +endfunction diff --git a/doc/put_date.txt b/doc/put_date.txt new file mode 100644 index 0000000..9fb7021 --- /dev/null +++ b/doc/put_date.txt @@ -0,0 +1,44 @@ +*put_date.txt* For Vim version 7.0 Last change: 2020 May 31 + +DESCRIPTION *put_date* + +This plugin provides a convenience wrapper around `strftime()` to insert the +current date and time in the buffer, defaulting to RFC2822 format, and +requiring neither percent signs nor quoting for any specified format. +> + :PutDate + Sun, 31 May 2020 01:04:41 +1200 + :PutDate d/m/Y + 31/05/2020 +< +An attempt to use the UTC time zone rather than the local time zone is made if +a bang is added: +> + :PutDate! + Sat, 30 May 2020 13:04:14 +0000 + :PutDate! + 13 +< +This time zone switching only works reliably on Unix with Vim v8.2, or Vim 8.1 +with patch 1567: + +REQUIREMENTS *put_date-requirements* + +This plugin only loads if 'compatible' is not set. Strictly speaking, it also +depends on the underlying system's implementation of the POSIX `strftime(3)` +function, just as Vim's own |strftime()| does. It will not behave identically +between systems. + +In particular, the time zone switching only works reliably on Unix, and it's +broken there between patches 8.1.1313 and 8.1.1567. See |version8.txt| for +details. At the time of writing, it's still broken on Windows since 8.1.1313. + +AUTHOR *put_date-author* + +Written and maintained by Tom Ryder . + +LICENSE *put_date-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/put_date.vim b/plugin/put_date.vim new file mode 100644 index 0000000..7848e95 --- /dev/null +++ b/plugin/put_date.vim @@ -0,0 +1,6 @@ +if exists('loaded_put_date') || &compatible || !exists('*strftime') + finish +endif +let loaded_put_date = 1 +command! -bang -bar -nargs=* -range PutDate + \ call put_date#(, ==# '!', ) -- cgit v1.2.3