From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id B90761F462 for ; Thu, 23 May 2019 13:41:42 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 42379120AB2; Thu, 23 May 2019 22:41:38 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 3E8A1120AAD for ; Thu, 23 May 2019 22:41:36 +0900 (JST) Received: by filter0151p3mdw1.sendgrid.net with SMTP id filter0151p3mdw1-29184-5CE6A311-5 2019-05-23 13:41:37.090578285 +0000 UTC m=+658982.548605102 Received: from herokuapp.com (unknown [184.73.130.48]) by ismtpd0040p1iad2.sendgrid.net (SG) with ESMTP id QDaBYGwhT8O0BheHsRNK7A for ; Thu, 23 May 2019 13:41:37.037 +0000 (UTC) Date: Thu, 23 May 2019 13:41:37 +0000 (UTC) From: nobu@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68283 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15772 X-Redmine-Issue-Author: osyo X-Redmine-Sender: nobu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?q8Dly+pU2+3ektTtZVXgZtbJPXwqo7p86jCsvYTW4BwVmjhLF5PsQveFHDDD4r?= =?us-ascii?Q?8NsH2iEOzuuNKoHAQuCqypULF3LwoIYw9cc47GC?= =?us-ascii?Q?onjPHGqOOoQPdI7n7k6v4FmBZJaYHIfM1dSfjEK?= =?us-ascii?Q?+ySdAMihkyowB5XYNxiLRQciIvZb+810CqrdyPV?= =?us-ascii?Q?+Wkv+AcW1MThnkeJJR7vnAkYe8ufAOoWT1g=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92799 Subject: [ruby-core:92799] [Ruby trunk Feature#15772] Proposal: Add Time#ceil X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15772 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Closed Closed by f5415a95ce1d393a3fd1d7f657ba85d85171356a I missed the tag to close the ticket. ---------------------------------------- Feature #15772: Proposal: Add Time#ceil https://bugs.ruby-lang.org/issues/15772#change-78173 * Author: osyo (manga osyo) * Status: Closed * Priority: Normal * Assignee: * Target version: ---------------------------------------- ## Summary proposal for a method that rounds up the decimal part of `Time` (nanosecond) to the specified digit. ## Current status * `Time#round` and `Time#floor` (https://bugs.ruby-lang.org/issues/15653) are defined. * However, `Time#ceil` is not defined. * So, I would like to respond flexibly when I would like to control decimal precision. ## Propose `Time#ceil` Below is example code. ```ruby require 'time' t = Time.utc(2010,3,30, 5,43,"25.0123456789".to_r) p t.iso8601(10) #=> "2010-03-30T05:43:25.0123456789Z" p t.ceil(0).iso8601(10) #=> "2010-03-30T05:43:26.0000000000Z" p t.ceil(1).iso8601(10) #=> "2010-03-30T05:43:25.1000000000Z" p t.ceil(2).iso8601(10) #=> "2010-03-30T05:43:25.0200000000Z" p t.ceil(3).iso8601(10) #=> "2010-03-30T05:43:25.0130000000Z" p t.ceil(4).iso8601(10) #=> "2010-03-30T05:43:25.0124000000Z" p t.ceil(5).iso8601(10) #=> "2010-03-30T05:43:25.0123500000Z" p t.ceil(6).iso8601(10) #=> "2010-03-30T05:43:25.0123460000Z" p t.ceil(7).iso8601(10) #=> "2010-03-30T05:43:25.0123457000Z" p t.ceil(8).iso8601(10) #=> "2010-03-30T05:43:25.0123456800Z" p t.ceil(9).iso8601(10) #=> "2010-03-30T05:43:25.0123456790Z" p t.ceil(10).iso8601(10) #=> "2010-03-30T05:43:25.0123456790Z" # default argument is 0 p t.ceil.iso8601(10) #=> "2010-03-30T05:43:26.0000000000Z" t = Time.utc(1999,12,31, 23,59,59) p (t + 0.4).ceil.iso8601(3) #=> "2000-01-01T00:00:00.000Z" p (t + 0.49).ceil.iso8601(3) #=> "2000-01-01T00:00:00.000Z" p (t + 0.5).ceil.iso8601(3) #=> "2000-01-01T00:00:00.000Z" p (t + 1.4).ceil.iso8601(3) #=> "2000-01-01T00:00:01.000Z" p (t + 1.49).ceil.iso8601(3) #=> "2000-01-01T00:00:01.000Z" p (t + 1.5).ceil.iso8601(3) #=> "2000-01-01T00:00:01.000Z" t = Time.utc(1999,12,31, 23,59,59) p (t + 0.123456789).ceil(4).iso8601(6) #=> "1999-12-31T23:59:59.123500Z" ``` pull request : https://github.com/ruby/ruby/pull/2133 -- https://bugs.ruby-lang.org/