微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

自定义日期时间模式 XSD

如何解决自定义日期时间模式 XSD

我试图找到一个更好的可读解决方案来匹配格式中的 DateTime 字符串:

2020 年 8 月 10 日星期一 18:53:56

PHP date format 中:

D M d H:i:s Y

我目前的解决方案是:

<xs:simpleType name="dateTimeType">
    <xs:restriction base="xs:string">
        <xs:pattern value="((Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (([0-2][0-9])|(3[0-1])) (([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9] [0-9]{4})?" />
    </xs:restriction>
</xs:simpleType>

我正在考虑这样的事情:

<xs:simpleType name="weekdayType">
    <xs:restriction base="xs:string">
        <xs:pattern value="Mon|Tue|Wed|Thu|Fri|Sat|Sun" />
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="monthType">
    <xs:restriction base="xs:string">
        <xs:pattern value="Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec" />
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="monthdayType">
    <xs:restriction base="xs:string">
        <xs:pattern value="([0-2][0-9])|(3[0-1])" />
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="timeType">
    <xs:restriction base="xs:string">
        <xs:pattern value="(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]" />
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="yearType">
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9]{4}" />
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="dateTimeType">
    <xs:restriction base="xs:string">
        <xs:pattern value="(weekdayType monthType monthdayType timeType yearType)?" />
    </xs:restriction>
</xs:simpleType>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。