Date configuration and settings

Video loading...

  • 0:01
    [Configurations & Settings] [Dates with Drupal 7] [Chapter 2] [With Karen Stevenson]
  • 0:06
    In this chapter, Karen is going to discuss the basic configurations of the date module
  • 0:10
    and basic configurations in general.
  • 0:12
    She'll begin with the modules required for the series
  • 0:15
    and move into setting date-related variables in core.
  • 0:18
    The steps that Karen discusses are the backbone
  • 0:21
    for all future date-related configurations and integration.
  • 0:25
    Today, we're going to take a look at the basic configuration of the date module
  • 0:29
    and basic configuration of dates in general.
  • 0:33
    I'm looking at a new installation--Drupal 7 Installation.
  • 0:37
    Nothing is installed yet, and the only thing I've got available right now
  • 0:42
    is the package that I downloaded for the date module from Drupal.org.
  • 0:47
    If I go to the Modules page, and I collapse the core information,
  • 0:51
    I can see that I have a whole lot of modules, and that's because the date package
  • 0:55
    is actually a whole suite of modules that can be used in various ways.
  • 1:00
    I might use some of them. I might use none of them.
  • 1:04
    We'll be talking as we go through the videos about what all these different options are
  • 1:09
    and how you can use them, but for now the only thing that we need
  • 1:13
    is we need the date API, and the date API is the core of all of the date functionality
  • 1:19
    and is required by everything else that the date module does.
  • 1:24
    Then we want to create some date fields, and for that,
  • 1:27
    we need to enable the date module and that makes date and time fields available
  • 1:33
    to be added to content,
  • 1:36
    and the last thing that we're going to do for right now is, we're going to enable
  • 1:39
    the date tools module.
  • 1:41
    The date tools module is a really handy tool that gives us a wizard that will
  • 1:48
    get us started really quickly with dates.
  • 1:51
    So for now, that's all I'm going to do is enable those.
  • 1:56
    When I do that, I get this message up here that says that the date API requires
  • 2:00
    that we set up the site time zone and first day of week settings,
  • 2:03
    and that we also set up the date format settings.
  • 2:06
    And what this is saying is that on the site that I'm using right now,
  • 2:11
    these variables have not yet been set,
  • 2:16
    and they need to be because the date module cares about how these things are set.
  • 2:22
    So if I click through the first one of them,
  • 2:25
    this is the regional settings.
  • 2:26
    The regional settings is where I identify my default country,
  • 2:30
    which I had to do as a part of the installation.
  • 2:33
    This is also where I set up the first day of the week,
  • 2:35
    and in the United States, we generally would have the first day of week be Sunday,
  • 2:40
    but it could be Monday or perhaps another day of the week.
  • 2:46
    The date module also adds this option to use the ISO-8601 week numbers.
  • 2:52
    This is not something that most people are using probably,
  • 2:56
    but if you're doing something with dates in a calendar, and you're in a country
  • 3:03
    that you uses ISO week numbers for calendars instead of calendar numbers,
  • 3:07
    which is a different kind of way of calculating what the week is,
  • 3:13
    then you can check this box.
  • 3:17
    If you do that, you have to set the first day of the week to Monday
  • 3:19
    because the ISO week numbers require that the first day of the week be Monday.
  • 3:24
    I'm in the United States. I don't need that, so I'm going to leave that unchecked.
  • 3:29
    I've got my time zone already set up, and I also see that I have a place
  • 3:32
    where I can designate whether or not users can set their own time zones.
  • 3:35
    All of these time zone configuration settings can play into the way that the date module works.
  • 3:43
    So I'm going to save that.
  • 3:45
    Then the second place that I need to fix is, if I go back to
  • 3:48
    the administration configuration screen, and I scroll down to the very bottom,
  • 3:54
    I can see this regional and language section.
  • 3:56
    These are core settings.
  • 3:59
    I already fixed the regional settings, but I need to also fix the date and time settings,
  • 4:03
    so I'm going to select that.
  • 4:06
    And this is the place where I can set up formats for the way that dates are displayed
  • 4:11
    on my site.
  • 4:13
    Now by default, I end up with the 24-hour clock because that's what Drupal does by default.
  • 4:19
    I'm in the United States. I'm going to change that.
  • 4:22
    So I'm going to change my long, medium, and short settings to match
  • 4:26
    the way that I want dates to be displayed in my system.
  • 4:29
    So in my system, I want to use the 12-hour clock, and then I'm going to do this,
  • 4:38
    where I'm showing the medium format is the full name of the month, the day, the year
  • 4:44
    and the time using the 12-hour clock.
  • 4:47
    Then for my short format, I want the month, day, year as numbers using the 12-hour clock.
  • 4:59
    That's my particular way that I want to set this up.
  • 5:02
    We're going to use this for the videos that we're working on right now,
  • 5:04
    but you can obviously set those up to match something appropriate for your site.
  • 5:11
    But there's another part to this.
  • 5:12
    In addition to these long, medium, short types, we can also in the format options
  • 5:18
    that come with it, we can also set up custom formats,
  • 5:22
    and there are a lot of formats that are really useful when you're using date fields
  • 5:28
    and using dates in general.
  • 5:29
    We're going to go ahead and set a few up.
  • 5:32
    Now nothing--no custom date formats are in here to begin with,
  • 5:36
    so we can add a new one.
  • 5:38
    We can see it just is a text area or text box where we can put in a date fomat string.
  • 5:45
    There's a link here to the PHP manual that describes what these things are.
  • 5:49
    I'm going to open this in a new tab just to make it easy to get to.
  • 5:54
    I'm going to go over here, and this is what date formats look like.
  • 5:59
    So date formats basically are a bunch of letters--a letter or a number of letters--
  • 6:04
    that describe how you want the date to look.
  • 6:07
    So for instance, a lowercase d says I want to see the day of the month in 2 digits
  • 6:12
    with leading 0's, so it would look like 01 to 31.
  • 6:15
    The j is the day of the month without leading 0's, so same thing as d--as the lowercase d,
  • 6:23
    except the leading 0 is left off.
  • 6:25
    The capital D says, I want to see the 3-letter abbreviation of the name of the day
  • 6:32
    and so forth.
  • 6:33
    You can read through this whole list, and you can see that there are letters here
  • 6:40
    that represent various ways that you can look at dates.
  • 6:45
    So what I want to do is, I want to create some additional formats that I've got available to me
  • 6:49
    in my system.
  • 6:51
    So 1 thing I might want to do is, there are places where I maybe only want
  • 6:54
    to be able to see a year, so I'm going to add the capital Y as a format
  • 6:58
    and a capital Y is the 4-digit year.
  • 7:02
    I'm going to add a format for a lowercase j, which is the day without the leading 0's,
  • 7:10
    and I think it would be nice to have a date format without the time,
  • 7:16
    and that would look like month/day/year because I'm in the United States,
  • 7:21
    and we use the month, day, year format, so I'm going to add that.
  • 7:27
    Then it might also be nice to have a time without a date,
  • 7:31
    and so if I do g, i, a--g means 12-hour clock:, i means minutes, and then a means a.m. or p.m.
  • 7:43
    I can see that as I type these options in, they are displayed over here to the right,
  • 7:48
    so I can kind of see what this is going to look like.
  • 7:50
    I add that.
  • 7:52
    That's pretty good, so I've got some additional options.
  • 7:56
    If I go back over here to the types, and I open up my options,
  • 8:00
    I can see that all these new custom options are now available to me as well as
  • 8:03
    the options that I saw before.
  • 8:06
    So that's one part of the equation.
  • 8:08
    I've got some new formats available to me, and I could say
  • 8:10
    I just want to change my short format to be a date only, for instance.
  • 8:14
    But in fact, I probably want to just leave these original formats alone--
  • 8:21
    or these original types alone--and add some new ones.
  • 8:23
    So I can add a new type, and I can call it date.
  • 8:26
    I could say my date format is this new format string that I just created
  • 8:31
    that displays the date without the time.
  • 8:35
    I can add a new type called time, and I can use, for that, I'll use that format
  • 8:41
    that I just created that has the time without the date.
  • 8:45
    Then I'm going to go ahead and add year that uses that format that I just created
  • 8:52
    that has just the year in it.
  • 8:55
    And I'm going to add day, and that's going to use this format that I created
  • 9:02
    that has nothing but the day.
  • 9:06
    So now I've got some nice additional formats available that I can use in various ways,
  • 9:13
    and I can use these things in views.
  • 9:15
    I can use them to format the way that my dates display.
  • 9:18
    I can use them anyplace that the system uses this long, medium, and short format options.
  • 9:25
    So let's go back to the modules page now.
  • 9:28
    We've got that set up.
  • 9:30
    Scroll down here, and when we enabled the date tools,
  • 9:36
    date tools has a configuration page, which is the page where you can actually
  • 9:40
    set up the date wizard.
  • 9:42
    It also has a permissions page, so let's take a quick look at that
  • 9:45
    and see what permissions we got.
  • 9:47
    If we scroll up a little bit, we can see that date tools comes with permission to administer
  • 9:53
    the date tools.
  • 9:54
    Now date tools, lets us do some very powerful things.
  • 9:57
    It lets us create new content types.
  • 9:59
    It lets us add fields to those content types.
  • 10:03
    So this is a permission that you'd want to restrict very carefully to just the highest level
  • 10:10
    of people.
  • 10:12
    Then I can go back down here and click on the configure link
  • 10:19
    and that takes me to the place where I can actually manage my date tools.
  • 10:27
    The main thing that the date tools has is the date wizard.
  • 10:31
    I'm just going to flip back and show you one more way that I can get there
  • 10:33
    rather than going through the modules page, if I go back to the configuration page,
  • 10:37
    and I scroll down, you can see that I've got a date API section
  • 10:41
    of the configuration page, and I also have a link there to get to this date tools.
  • 10:48
    So let's go ahead and use the date wizard to get us started real quickly.
  • 10:53
    What it does, basically, is it says it's going to automatically create a content type,
  • 10:58
    and then attach a date field to it and set it up in a good basic way,
  • 11:05
    so you don't have to go through all of the individual steps of creating the content type
  • 11:09
    and adding the field.
  • 11:11
    If you have the calendar module enabled, it also is going to give you an option
  • 11:14
    to create a calendar at the same time.
  • 11:17
    We don't have the calendar enabled, and we'll be showing that kind of thing later.
  • 11:23
    So right now, we're just going to create a date content type and a date field.
  • 11:27
    If I scroll down, I can see that for the content type I can choose the content type name,
  • 11:32
    and this is the machine-readable name and then the label,
  • 11:35
    which is the human-readable name,
  • 11:37
    and then a description, and in this case, we're not linking this to a calendar,
  • 11:42
    so I'm just going to change this description a little bit.
  • 11:47
    Then down here a little bit farther, we have the place where we can set up the date field
  • 11:53
    and the date field name, and this is the machine-readable name for the date field
  • 11:59
    that we're going to create in the label.
  • 12:01
    Then I have an option of a text field or a select widget for the type of widget,
  • 12:09
    and I would have other options if I had other modules enabled,
  • 12:12
    which we'll demonstrate later.
  • 12:14
    There's some advanced options.
  • 12:16
    I can make some additional changes to time zone handling and granularity,
  • 12:20
    and we're going to talk about all those options later,
  • 12:23
    but for right now, we're just going to create something that uses the defaults.
  • 12:29
    So you can see that what we ended up with is, we ended up with a content type called date.
  • 12:34
    It has a title. It has a date field, and it has a description.
  • 12:39
    Let's go ahead and just try adding some content to see what this is going to look like.
  • 12:45
    So I've got a new content type, and this is my test date,
  • 12:52
    and I can choose whether or not it's got an end date,
  • 12:54
    and let's do 10:45 to 11:45 on April 3rd, and my description goes here.
  • 13:08
    So I can put whatever into my description, and I save it.
  • 13:12
    There we go!
  • 13:14
    In just a couple of steps, I got to the point where I had a date.
  • 13:19
    Now one thing looks a little bit funny, and that is my date is below the description,
  • 13:24
    and in fact, I would have wanted that date to be above the description,
  • 13:27
    so let's go back and see what happened there and fix it real quickly.
  • 13:31
    So if I go on my structure to the content types area,
  • 13:35
    I can see where my date content type is.
  • 13:37
    There is a link here to the manage display for the date field,
  • 13:42
    and you can see that it looks like the date is above the description,
  • 13:46
    so it, in fact, is where it belongs, but it's not showing up right,
  • 13:50
    and this is actually nothing to do with the date module.
  • 13:53
    This is just a quirk in the way that this draggable table in the field UI works.
  • 13:59
    All I have to do is move them and move them back just to trigger the fact
  • 14:04
    that there's a change and save it.
  • 14:06
    Now if I go back and take a look at that content that I just created,
  • 14:10
    now I've got it where I want.
  • 14:12
    The date is on top, and the description is below.
  • 14:15
    Now the last thing that I want to do in this initial step to get started
  • 14:19
    is I want to create some content.
  • 14:20
    I'm going to create some views. I want to do some different things.
  • 14:23
    It would be nice to have a lot of content that already has dates on it.
  • 14:27
    So let's go try and do that.
  • 14:30
    If I go back to modules, I previously downloaded the Devel module--D-E-V-E-L.
  • 14:38
    The Devel module comes with something called Devel generate,
  • 14:41
    which is a really nice tool for creating dummy content,
  • 14:48
    just for cases like this.
  • 14:50
    So I'm going to enable Devel generate, and it requires Devel,
  • 14:53
    so I'm going to enable both of those, and I'm going to save that.
  • 14:59
    If I go to the configuration area now, and I scroll down.
  • 15:04
    I can see that I now have some options to generate content, menus, terms, users.
  • 15:08
    I'm going to go ahead and generate some content, and I want to generate content
  • 15:12
    of the type date, and I could choose to delete all content if I had some content in there.
  • 15:19
    In fact, I created that one little dummy note, and I'm going to go ahead and delete that
  • 15:24
    at the same time I create some new dummy content.
  • 15:28
    I can choose how far back into the time the nodes should be created--
  • 15:31
    or should be dated.
  • 15:32
    Now this does not have anything to do with the date field date.
  • 15:37
    This is the creation date of the node, but it's nice when you get to things like views
  • 15:42
    to have things scattered over a period of time.
  • 15:45
    I'm going to go ahead and say--I'm going to go back a year.
  • 15:50
    I'm just going to go ahead and generate,
  • 15:53
    and it says I finished--I deleted the one node that I had previously created,
  • 15:57
    and I created 15 new nodes, and if I go to find content,
  • 16:02
    and I go take a look at one of them, I can see now I have dummy content,
  • 16:06
    and my dummy content has dates on it.
Loading ...

Date Configuration and Settings

Loading...

In this chapter, Karen turns on the Date, Date API, and Date tools modules, and walks us through some initial configuration of core date settings, so that we can use Date module properly. We look at the site timezone settings, as well as talk about the core date formats. Then we go ahead and create some new custom date formats and date types.

Additional resources: