Add a saturating `adjust` variant?

Đang mở
#90 0 bình luận 3 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Lĩnh vực
backend

Hướng nghiên cứu

The issue proposes a saturating shift variant of adjust in the DateTime library. Start by reading the existing adjust implementation and the Duration type; decide whether saturating behavior is appropriate and how bounds should be represented. Done means the API design is agreed on and the requested variant is specified.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

status: needs more info

While writing an app with lots of DateTime manipulations, I noticed that adjust is very annoying to use, because of the Maybe return type. I don't think this is a very practical design, similarly to how (+) :: Int -> Int -> Maybe Int wouldn't be. There is often not much you can do on failure, other than just skip the operation. Needless to say, that doesn't help with correctness.

I think that saturating semantics would make more sense. Something like this:

-- | Like `adjust`, but saturates on out-of-bounds results.
shift :: forall d. Duration d => d -> DateTime -> DateTime
shift d dt = case adjust d dt of
    Nothing -> if fromDuration d > mempty then top else bottom
    Just d' -> d'

Does this sound like a good idea? I can make it into a PR, but wanted to get some feedback first.

Ngôn ngữ chính
PureScript
Star
51
Fork
48
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của purescript/purescript-datetime

Tất cả issue của purescript/purescript-datetime

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.