Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev.icinga.com #9839] Implement support for formatting date/time #3224

Closed
icinga-migration opened this issue Aug 5, 2015 · 18 comments
Closed
Labels
area/configuration DSL, parser, compiler, error handling blocker Blocks a release or needs immediate attention enhancement New feature or request
Milestone

Comments

@icinga-migration
Copy link

This issue has been migrated from Redmine: https://dev.icinga.com/issues/9839

Created by bsheqa on 2015-08-05 09:37:25 +00:00

Assignee: gbeutner
Status: Resolved (closed on 2016-04-21 11:31:56 +00:00)
Target Version: 2.5.0
Last Update: 2016-05-02 07:19:23 +00:00 (in Redmine)

Backport?: Not yet backported
Include in Changelog: 1

It would be nice to have a date() function which could be used for services. The function should support multiple formats, like 'date' on linux.

This is an example on how it may look:

object Service "logfile" {
      import "generic-service"
  display_name = "logfile"
  host_name = "herp.derp.com"
    vars.logfiles_logfile = {{ "/var/log/logfile-" + Date.format("%Y-%m-%d") }}
    check_command = "check_logfiles"
}

Changesets

2016-03-29 11:22:34 +00:00 by (unknown) 47575eb

Implement the DateTime class

fixes #9839

2016-03-29 11:27:20 +00:00 by (unknown) eb08922

Implement the DateTime class

fixes #9839

2016-03-29 12:52:48 +00:00 by (unknown) 112f024

Build fix for GCC

refs #9839

2016-04-21 11:31:12 +00:00 by gbeutner 5af437b

Add documentation for the DateTime type

fixes #9839

2016-04-21 12:04:56 +00:00 by gbeutner 46ff7bd

Fix incorrect links in the documentation

refs #9839

Relations:

@icinga-migration
Copy link
Author

Updated by mfrosch on 2015-08-06 10:57:30 +00:00

  • Subject changed from Date function to Date object
  • Target Version set to Backlog

We should provide a Date object to format dates and output them via config calls.

Output should be provided via functions, not macros :)

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2015-08-06 20:34:03 +00:00

  • Category set to Configuration

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2015-09-05 14:47:26 +00:00

  • Target Version deleted Backlog

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2015-09-05 15:08:36 +00:00

  • Priority changed from Normal to High

@icinga-migration
Copy link
Author

Updated by gbeutner on 2015-10-14 13:10:43 +00:00

  • Description updated

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-02-24 23:42:49 +00:00

  • Target Version set to Backlog

@icinga-migration
Copy link
Author

Updated by dgoetz on 2016-02-25 09:49:56 +00:00

It would also be nice to have the possibility to compare dates like in this use case.

I want create an internal check to notify someone if a date set as customvariable is reached. This necessary for a tool handling certificates requiring to be renewed every year as a black box.

This would require a function for the date object to get "now" and some comparison operators.

@icinga-migration
Copy link
Author

Updated by Anonymous on 2016-03-29 11:22:41 +00:00

  • Status changed from New to Resolved
  • Done % changed from 0 to 100

Applied in changeset 47575eb.

@icinga-migration
Copy link
Author

Updated by gbeutner on 2016-03-29 11:22:57 +00:00

  • Assigned to set to gbeutner
  • Target Version changed from Backlog to 2.5.0

Still needs documentation.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-03-29 11:27:45 +00:00

  • Status changed from Resolved to Assigned

@icinga-migration
Copy link
Author

Updated by Anonymous on 2016-03-29 11:30:03 +00:00

  • Status changed from Assigned to Resolved

Applied in changeset eb08922.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-03-29 11:35:51 +00:00

  • Status changed from Resolved to Assigned

Support arbitrarily long format strings in Utility::FormatDateTime().

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-03-29 15:02:57 +00:00

For reference:

mbmif ~ # icinga2 console
Icinga 2 (version: v2.4.4-284-g47575eb)
<1> => datetime
       ^^^^^^^^
Error while evaluating expression: Tried to access undefined script variable 'datetime'
<2> => Datetime
       ^^^^^^^^
Error while evaluating expression: Tried to access undefined script variable 'Datetime'
<3> => DateTime
{
    base = {
        base = null
        name = "Object"
        prototype = {
            clone = {
                type = "Function"
            }
            notify_attribute = {
                type = "Function"
            }
            to_string = {
                type = "Function"
            }
        }
        type = "Type"
    }
    name = "DateTime"
    prototype = {
        format = {
            type = "Function"
        }
    }
    type = "Type"
}
<4> => d = DateTime()
null
<5> => d
{
    type = "DateTime"
    value = 1459251226.528245
}
<6> => d.to_string()
"2016-03-29 13:33:46 +0200"
<7> => d.format()
       ^^^^^^^^^^
Error while evaluating expression: Too few arguments for function.
<8> => d.format("%Y-%m-%d")
"2016-03-29"
<9> => d.format("%Y-%m-%d %S")
"2016-03-29 46"
<10> => d.format("%Y-%m-%d %H:%M:%S")
"2016-03-29 13:33:46"
<11> => d.format("%Y-%m-%d %H:%M:%S %D")
"2016-03-29 13:33:46 03/29/16"
<12> => d.format("%Y-%m-%d %H:%M:%S %Z")
"2016-03-29 13:33:46 CEST"
<13> => e = DateTime(1459251418)
null
<14> => e.format("%Y-%m-%d %H:%M:%S %Z")
"2016-03-29 13:36:58 CEST"
<15> => f = e - d
null
<16> => f
191.471755
<17> => d + 3600
{
    type = "DateTime"
    value = 1459254826.528245
}
<18> => (d + 3600).to_string()
"2016-03-29 14:33:46 +0200"
<19> => (d - 3600).to_string()
"2016-03-29 12:33:46 +0200"
<20> => g = DateTime(2016, 3, 29)
null
<21> => g
{
    type = "DateTime"
    value = 1459202400.000000
}
<22> => String(g)
"2016-03-29 00:00:00 +0200"
<23> => g = DateTime(2016, 3, 29, 13, 40, 36)
null
<24> => String(g)
"2016-03-29 13:40:36 +0200"
<25> => g > d
true
<26> => g < d
false
<27> =>

@icinga-migration
Copy link
Author

Updated by gbeutner on 2016-04-21 11:31:56 +00:00

  • Status changed from Assigned to Resolved

Applied in changeset 5af437b.

@icinga-migration
Copy link
Author

Updated by gbeutner on 2016-04-21 11:32:13 +00:00

  • Target Version changed from 2.5.0 to 2.4.8

@icinga-migration
Copy link
Author

Updated by gbeutner on 2016-04-21 12:07:06 +00:00

  • Subject changed from Date object to Implement support for formatting date/time

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-05-02 07:19:23 +00:00

  • Target Version changed from 2.4.8 to 2.5.0

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2016-05-13 16:29:01 +00:00

  • Duplicated set to 11789

@icinga-migration icinga-migration added blocker Blocks a release or needs immediate attention enhancement New feature or request area/configuration DSL, parser, compiler, error handling labels Jan 17, 2017
@icinga-migration icinga-migration added this to the 2.5.0 milestone Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration DSL, parser, compiler, error handling blocker Blocks a release or needs immediate attention enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant