All Projects → eddelbuettel → Anytime

eddelbuettel / Anytime

Licence: gpl-2.0
Anything to POSIXct or Date Converter

Programming Languages

r
7636 projects
cpp11
221 projects

Projects that are alternatives of or similar to Anytime

Zulu
A drop-in replacement for native Python datetimes that embraces UTC.
Stars: ✭ 52 (-62.04%)
Mutual labels:  date, datetime
Carbon
A simple PHP API extension for DateTime
Stars: ✭ 75 (-45.26%)
Mutual labels:  date, datetime
Laydate
layDate(日期与时间组件) 是 layui 独立维护的三大组件之一
Stars: ✭ 1,066 (+678.1%)
Mutual labels:  date, datetime
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+27179.56%)
Mutual labels:  date, datetime
Dateparse
GoLang Parse many date strings without knowing format in advance.
Stars: ✭ 1,365 (+896.35%)
Mutual labels:  date, datetime
Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (+622.63%)
Mutual labels:  date, datetime
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (-48.91%)
Mutual labels:  date, datetime
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (+291.24%)
Mutual labels:  date, datetime
Luatz
Time, Date and Timezone library for lua
Stars: ✭ 92 (-32.85%)
Mutual labels:  date, datetime
Graphql Java Datetime
GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphql-java.
Stars: ✭ 89 (-35.04%)
Mutual labels:  date, datetime
Vue Datetime
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
Stars: ✭ 928 (+577.37%)
Mutual labels:  date, datetime
Calendar
📅 PHP Date & Time library that solves common problems in object oriented, immutable way.
Stars: ✭ 113 (-17.52%)
Mutual labels:  date, datetime
Period
PHP's time range API
Stars: ✭ 616 (+349.64%)
Mutual labels:  date, datetime
Nanotime
Nanosecond Resolution Time Functionality for R
Stars: ✭ 39 (-71.53%)
Mutual labels:  datetime, cran
Carbon
A simple, semantic and developer-friendly golang package for datetime
Stars: ✭ 565 (+312.41%)
Mutual labels:  date, datetime
When
A natural language date/time parser with pluggable rules
Stars: ✭ 1,113 (+712.41%)
Mutual labels:  date, datetime
Jedate
jeDate V6.5.0 是一款原生JS开发的 不依赖任何第三方库 大众化的日期控件,她身兼多职,虽不是万能的,但是她却是功能强大多样的美少女,她除了包含 单双面板、区域选择、 多语言、日历固定、有效无效日期、日期时间戳转换、日期加减、限制时分秒、初始化日期加减N、日期标注点、设定年月(YYYY-MM)、日期范围限制、开始日期设定、自定义日期格式、当天的前后若干天返回、时分秒选择、智能响应、自动纠错、节日识别,操作等常规功能外,根据不同的日期格式,显示不同内容,还拥有更多趋近完美的解决方案。更多的是需要你与她的亲密接触与呵护!
Stars: ✭ 433 (+216.06%)
Mutual labels:  date, datetime
Pendulum
Python datetimes made easy
Stars: ✭ 4,639 (+3286.13%)
Mutual labels:  date, datetime
Rc Datetime Picker
React component for datetime picker by Moment.js
Stars: ✭ 85 (-37.96%)
Mutual labels:  date, datetime
Time Stamp
Get a formatted timestamp. Used in gulp, assemble, generate, and many others.
Stars: ✭ 104 (-24.09%)
Mutual labels:  date, datetime

anytime: Anything to 'POSIXct' or 'Date' Converter

Build Status CI License CRAN Dependencies CRAN use Downloads Code Coverage Last Commit Documentation JOSS

Motivation

R excels at computing with dates, and times. Using typed representation for your data is highly recommended not only because of the functionality offered but also because of the added safety stemming from proper representation.

But there is a small nuisance cost in interactive work as well as in programming. Users must have told as.POSIXct() about a million times that the origin is (of course) the epoch. Do we really have to say it a million more times? Similarly, when parsing dates that are some form of YYYYMMDD format, do we really have to manually convert from integer or numeric or factor or ordered to character? Having one of several common separators and/or date / time month forms (YYYY-MM-DD, YYYY/MM/DD, YYYYMMDD, YYYY-mon-DD and so on, with or without times), do we really need a format string? Or could a smart converter function do this?

anytime() aims to be that general purpose converter returning a proper POSIXct (or Date) object no matter the input (provided it was somewhat parseable), relying on Boost date_time for the (efficient, performant) conversion. anydate() is an additional wrapper returning a Date object instead.

Documentation

Package documentation, help pages, a vignette, and more is available here.

Examples

We show some simple examples on Date types.

(Note that in the first few examples, and for numeric conversion in this range we now only use anydate as anytime is consistent in computing seconds since epoch. If you want the behaviour of version older than 0.3.0, set oldHeuristic=TRUE, see help(anytime) for more.)

From Integer or Numeric or Factor or Ordered

library(anytime)                      ## also caches TZ in local env
options(digits.secs=6)                ## for fractional seconds below

## integer
anydate(20160101L + 0:2)              ## older version used anytime for this too
[1] "2016-01-01 CST" "2016-01-02 CST" "2016-01-03 CST"

## numeric
anydate(20160101 + 0:2)
[1] "2016-01-01 CST" "2016-01-02 CST" "2016-01-03 CST"

## factor
anydate(as.factor(20160101 + 0:2))
[1] "2016-01-01 CST" "2016-01-02 CST" "2016-01-03 CST"

## ordered
anydate(as.ordered(20160101 + 0:2))
[1] "2016-01-01 CST" "2016-01-02 CST" "2016-01-03 CST"

Character: Simple

## Dates: Character
anydate(as.character(20160101 + 0:2))
[1] "2016-01-01 CST" "2016-01-02 CST" "2016-01-03 CST"

## Dates: alternate formats
anydate(c("20160101", "2016/01/02", "2016-01-03"))
[1] "2016-01-01 CST" "2016-01-02 CST" "2016-01-03 CST"

Character: ISO

## Datetime: ISO with/without fractional seconds
anytime(c("2016-01-01 10:11:12", "2016-01-01 10:11:12.345678"))
[1] "2016-01-01 10:11:12.000000 CST" "2016-01-01 10:11:12.345678 CST"

## Datetime: ISO alternate (?) with 'T' separator
anytime(c("20160101T101112", "20160101T101112.345678"))
[1] "2016-01-01 10:11:12.000000 CST" "2016-01-01 10:11:12.345678 CST"

Character: Textual month formats

## ISO style
anytime(c("2016-Sep-01 10:11:12", "Sep/01/2016 10:11:12", "Sep-01-2016 10:11:12"))
[1] "2016-09-01 10:11:12 CDT" "2016-09-01 10:11:12 CDT" "2016-09-01 10:11:12 CDT"

## Datetime: Mixed format (cf https://stackoverflow.com/questions/39259184)
anytime(c("Thu Sep 01 10:11:12 2016", "Thu Sep 01 10:11:12.345678 2016"))
[1] "2016-09-01 10:11:12.000000 CDT" "2016-09-01 10:11:12.345678 CDT"

Character: Dealing with DST

This shows an important aspect. When not working localtime (by overriding to UTC) the changing difference UTC is correctly covered (which the underlying Boost Date_Time library does not by itself).

## Datetime: pre/post DST
anytime(c("2016-01-31 12:13:14", "2016-08-31 12:13:14"))
[1] "2016-01-31 12:13:14 CST" "2016-08-31 12:13:14 CDT"
anytime(c("2016-01-31 12:13:14", "2016-08-31 12:13:14"), tz="UTC")  # important: catches change
[1] "2016-01-31 18:13:14 UTC" "2016-08-31 17:13:14 UTC"

Technical Details

The heavy lifting is done by a combination of Boost lexical_cast to go from anything to string representation which is then parsed by Boost Date_Time. We use the BH package to access Boost, and rely on Rcpp for a seamless C++ interface to and from R.

Further, as the Boost Date_Time library cannot resolve timezones on the Windows platform (where timezone information is typically provided by R itself for its use), we offer a fallback of calling into R (via facilities from Rcpp); see the help for the useR argument for more details.

Status

The package should work as expected.

Example Uses

Several different CRAN packages import this package. Among them are the following research-focused packages:

  • adheRenceRX by Beal assesses medication adherence;
  • AGread by Hibbing et al which reads and transforms ActiGraph physical activity measures;
  • cqcr by Odell accesses 'Care Quality Commission' data from the health and adult social care regulator for England;
  • datadogr by Yutani queries metrics from Datadog;
  • E4tools by Kleiman which reads data from Empatica wearable physiology monitors;
  • nprcgenekeepr by Raboin et al provides genetic tools for colony management ;
  • RDS by Handcock et al which is part of the "RDS Ananlyst" suite for analysing respondent-driven sampling data;
  • rtsdata by RTSVizTeam manages time series data dtorage;
  • threesixtygiving by Odell accesses download charitable grants from the '360Giving' Platform;
  • tsbox by Sax for format-agnostic time series data representation and conversions;
  • tsibble by Wang et al for temporal data in an explicit data- and model-oriented format.

Changes

See the NEWS.Rd file on CRAN or GitHub. In particular, version 0.3.0 corrects an overly optimistic heuristic for integer or numeric arguments and now behaves more like R itself. Specifically, epoch offsets are interpreted as seconds for datetime objects, and days for date objects. The prior behaviour can be restored with an option which also be be set globally, see the help page for details.

Installation

The package is now on CRAN and can be installed via a standard

install.packages("anytime")

Continued Testing

As we rely on the tinytest package, the already-installed package can also be verified via

tinytest::test_package("anytime")

at any later point.

Contributing

Any problems, bug reports, or features requests for the package can be submitted and handled most conveniently as Github issues in the repository.

Before submitting pull requests, it is frequently preferable to first discuss need and scope in such an issue ticket. See the file Contributing.md (in the Rcpp repo) for a brief discussion.

Author

Dirk Eddelbuettel

License

GPL (>= 2)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].